title: Passing data between threads in c#
body: <p>I've found few questions concerning my problem but still, I couldn't hande with this on my own so I'll try to ask in here. I'll paste the code so I think it will be easier to explain.</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
          Thread thread = new Thread(new ThreadStart(StartCalculation));
          thread.Start();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
  
      }
  
  
      public void StartCalculation()
      {
          List&lt;int&gt; numbers = new List&lt;int&gt;();
          for (int i = 0; i &lt;= 100; i++)
          {
              numbers.Add(i);
              string textForLabel = i.ToString();
              label.SafeInvoke(d =&gt; d.Text = textForLabel);
          }
  
      }  
  }
  </code></pre>
  
  <ul>
  <li>I would like to have an acces from method StartCalculation which started in different thread. I'd like to access that int list from Form1 (10 elements after 10 secs, 20 elements after 20 secs and so). Is that possible?</li>
  <li>Would creating list in Form1() and then changing it in StartCalculation be possible?
  Thanks for the answers :)</li>
  </ul>
  
  <p>Edited for Groo- / -</p>
  
  <pre><code>public partial class Form1 : Form
  {
  
  List&lt;int&gt; list = new List&lt;int&gt;(); // list of int values from game's memory
  
  public Form1()
  {
      InitializeComponent();
      Thread thread = new Thread(new ThreadStart(refreshMemory));
      thread.Start();
      Thread thread2 = new Thread(new ThreadStart(checkMemory));
      thread2.Start();
  }
  
  private void Form1_Load(object sender, EventArgs e)
  {
  }
  
  public void refreshMemory()
  {        
      while (true)
      {
       // ... refresh game's memory and then, refresh list //
      Thread.Sleep(100);
      }
  }  
  
  public void checkMemory()
  {
  
      while (true)
      {
       // eg. if (list[0] == 5) {game:: move_right()}// 
      Thread.Sleep(100);
      }
  
  }  
  
  }
  </code></pre>
  
  <p>I'm making game bot. I want it to read game's memory in a different thread (changing memory list) and then, with few other methods (in different threads) I'd like to read from that list and do game actions depending on the memory values. It works (or just seem to be) but if You say it might be unsafe, I'd like to make it safe.  </p>
  
  <p>Hope I haven't made fool out of myself by pasting it here.</p>