I'm learning about threads and how to work with them right now. Simultaneously, I'm honing my comprehension of events/global events (just for context).
I created a thread inside an object and gave it a function to utilise on thread.Start()
internal class Name
private Thread testthread;
private EventWaitHandle globalEvent;
private Eventstest evente = new Eventstest(); //Just to add some methods
public Name(Thread testthread, EventWaitHandle globalEvent)
this.testthread = testthread;
this.globalEvent = globalEvent;
public void Execute()
bool terminate = false;
bool eventset = false;
bool rdy = false;
eventset = true; //This is just to check with debugger if the event was raised elsewhere
So, in this example in a Windows Forms App, I'm attempting to create an instance of this class while also creating an instance of the thread (with the work method the should run later on). This is where I'm having trouble.
private void btn_runThread_Click(object sender, EventArgs e)
threadClass = new Name(new Thread(ProblemHere), globalEvent);
This is a button that starts the thread working on the task at hand. In forms1.cs, the variable threadClass is simply the initialization:
I understand that it requires a delegate to pass the thread's start method. I tried everything I could think of and couldn't get it to work. I can't just call the method and expect it to work. And, as far as I can tell, the material I found in the c# documentation is basically just passing the function. Which is most likely incorrect. And, as I just realised, if the property/thread.start is only created at runtime, how am I able to use it?