EDIT: Question answered. Answer explained perfectly by Igor. (Thank you!)
Question: How do I access/control a thread from another class in the same program? I'm will be having multiple threads active (not all at once) and I need to check if one is active (that is not the main thread).
I am programming in C# and I am trying to use threading. I have 2 classes, my thread starts in the main class calling a function in the other class. In my other class I want to see if "thread.isAlive == true" but I think it isn't publicly available. I don't know the syntax/code to be able to use the thread from another class? I'm struggling to get it working.
I can call the other class, but I can't call the thread between classes. (Can't declare a thread outside of a class) The error thrown is:
Error 1 The name 'testThread' does not exist in the current context
Example code:
//Headers
using System.Threading;
using System.Threading.Tasks;
namespace testProgram
{
public class Form1 : Form
{
public void main()
{
//Create thread referencing other class
TestClass test = new TestClass();
Thread testThread = new Thread(test.runFunction)
//Start the thread
testThread.Start();
}//Main End
}//Form1 Class End
public class TestClass
{
public void runFunction()
{
//Check if the thread is active
//This is what I'm struggling with
if (testThread.isAlive == true)
{
//Do things
}//If End
}//runFunction End
}//testClass End
}//Namespace End
Thanks for reading! -Dave