title: Accessing Class members with Invoke from a different thread in C#
body: <p><strong>Note</strong>: Part of a series: <a href="https://stackoverflow.com/questions/717264/c-accessing-form-members-from-another-class">C#: Accessing form members from another class</a> and <a href="https://stackoverflow.com/questions/717074/how-to-access-form-objects-from-another-cs-file-in-c">How to access form objects from another cs file in C#</a>.</p>
  
  <hr>
  
  <p>Hello,</p>
  
  <p>The Idea is to notify the user using the memo when a packet is received/sent in a TCP Client.</p>
  
  <p>After couple of fixes,the most suitable solution seemed to be this one</p>
  
  <pre><code>    public string TextValue
      {
          set
          {
              this.Memo.Text += value + "\n";
          }
      }
  </code></pre>
  
  <p>That's how it's being called</p>
  
  <pre><code>    var form = Form.ActiveForm as Form1;
      if(form != null)
          form.TextValue = "Test asdasd";
  </code></pre>
  
  <p>However,calling the code throws an exception ,because of Unsafe thread call.I found a solution at <a href="http://msdn.microsoft.com/en-us/library/ms171728.aspx" rel="nofollow noreferrer">msdn</a>,but I can't seem to acquire the method they've used there.</p>
  
  <p>This is my remake,which doesn't work.</p>
  
  <pre><code>    private void SetTextMemo(string txt)
      {
          if(this.Memo.InvokeRequired)
          {
              this.Invoke(SetTextMemo,txt); //error here
          }
          else
          {
              this.Memo.Text += txt + "\n";
          }
      }
  </code></pre>
  
  <p>errors:</p>
  
  <p>Argument '1': cannot convert from 'method group' to 'System.Delegate'</p>
  
  <p>Argument '2': cannot convert from 'string' to 'object[]'</p>
  
  <p>Basically,I'm trying to access the Memo(or more likely said,add text to the memo) from another thread using Invoke.I never used it before,maybe that's why I misunderstand my mistake.</p>