Passing Data Between

If we want to share data between threads we can use a common reference or a static field
You can share data between different threads by using a public or static field.


public static void Main() 
{
   MyClass obj = new MyClass();
   obj.message = "some text";
   new System.Threading.Thread (obj.Method_Run).Start();

   Console.ReadLine();
   System.Console.WriteLine(obj.newtext):
}

public class MyClass()
{
   public string mytext;
   public string newtext;
  
   public void Method_Run()
   {
      System.Console.WriteLine(mytext);
      newtext = "new text";
   }
}


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext