I am digging into multithreading, found some good tutorials but I have some remaining questions.
I figured how to run one function async, (see this tutorial) there are four examples to archieve that.
But in the application I am developping I want to run an entire class in a seperate thread. I’m looking for something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace multithread_test
{
class Program
{
Program()
{ }
RunInBackground RIB;
void StartBackgroundWorker()
{
// how do I get RIB to run in the background?
RIB = new RunInBackground();
}
//somefunction to listen to the CallEventToUpdateGUI
}
//This class should run in a different thread than class Program
class RunInBackground
{
void RunInBackground()
{ }
void Function1()
{
//somefunction
}
void Function2()
{
// somefunction
}
void Function3()
{
Function1();
}
void CallEventToUpdateGUI()
{
//call a event to update gui
}
}
Thread is about execution of the code and not about definiton of it. You can not do this.
What you can do is only run the code on ohter thread.
You also can instantiate a class on another thread, but it’s by the way is not a definition of it.