I'd like some ideas of how I can make a thread in C# to work as kind of an entity, where it stays "waiting" for me to call some method, and then that method will be executed inside that thread, and not on the thread that called the method.
Let me give an example:
public class ThreadClass
{
public void method1() { do something...}
public void method2() { do something...}
public void method3() { do something...}
} //my class with methods I want to run in another thread than UI, no order specific, when I need it...
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
//call method1, but it CANNOT RUN IN UI THREAD
}
private void button2_Click(object sender, EventArgs e)
{
//call method2, but it CANNOT RUN IN UI THREAD
}
} //main thread and class
To sum up: My thread has to live "forever", doing nothing, and when I click some button etc, some method will run inside it.
I've tried to use while loop, but I don't know how to call different methods in random moments.