title: Passing a Property by Reference
body: <p>I have a number of progress bars each bound to their own int property which updates their progress. Behind the scenes, I have a method that is being run multiple times which does my processing (looping through data) which I use to use to update the property which updates the progress bar.</p>
  
  <p>The problem I'm having is you cannot pass a property to the method. I could create multiple copies of the method, each referring to the specific property per progress bar but this would require a lot of duplicate code. How would one recommend I go about passing the property to the method?</p>
  
  <p>Essentially this is what I am trying to do but obviously passing the property by ref won't work.</p>
  
  <pre><code>Method(fileList, errorList, _ViewModel.ProgressBarProp1);
  Method(fileList, errorList, _ViewModel.ProgressBarProp2);
  ...
  
  private static void Method(IEnumerable&lt;string&gt; fileList, List&lt;Tuple&lt;string, 
      string&gt;&gt; errorList, ref int PropertyInt)
  {
      foreach (var file in fileList)
      {
          if (!File.Exists(file))
          {
              errorList.Add(new Tuple&lt;string, string&gt;(file,
                  " does not exist in the folder"));
          }
  
          PropertyInt++;
      }
  }
  </code></pre>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/1402803/passing-properties-by-reference-in-c-sharp">this question</a> but this deals with Strings and I haven't been able to implement any of the solutions for an Integer scenario.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Implementing Mike's solution below is allowing access to the property from within the method but I'm having some odd behaviour with the way I am running this concurrently.</p>
  
  <p>I'm implementing the code like so, two methods run simultaneously but incrementing the same property value (i.e. both are associated to the same progressbar). </p>
  
  <pre><code>var taskList = new List&lt;Task&gt;
  {
      Task.Run(() =&gt;
      {
          Method1(fileList, errorList, p =&gt; _ViewModel.ProgressBarProp1 = p);
      }),
      Task.Run(() =&gt;
      {
          Method2(fileList, errorList, p =&gt; _ViewModel.ProgressBarProp1 = p);
      })
  };
  await Task.WhenAll(taskList.ToArray());
  </code></pre>
  
  <p>However, only one appears to be updating. What would be the reason and is there a work around?</p>