In my code im running a thread. What I need to do now is to pass a variable to “SayHello” method. Since it is calling in a separate thread my variables are not visible for the thread.
ThreadStart ts = new ThreadStart(SayHello);
mThread = new Thread(ts);
mThread.Start();
Im new to C# and please let me know how to do this.
this is how I pass values. First, your parameter must be a object, so you need to cast in your method. Your method must return void, if you need to return values, you can do it in many ways, volatile variables, or thread communication, etc. Then:
And in your method:
If you need to pass more than one variable, then create a class and assign your values to properties, and cast in your method, but there are other ways to archive this. Hope this helps. If you need more info, chech this
link: Threading in C#
Good luck!