If I understood your question correctly, it could be anwser:
private void MethodStarter()
{
Task myFirstTask = Task.Factory.StartNew(() => Method1(5));
Task mySecondTask = Task.Factory.StartNew(() => Method2("Hello"));
}
private void Method1(int someNumber)
{
}
private void Method2(string someString)
{
}
If you want to start all threads at once, you can use the example specified by h1ghfive.
UPDATE:
An example with a callback that should work, but I have not tested it.
private void MethodStarter()
{
Action<int> callback = (value) => Console.WriteLine(value);
Task myFirstTask = Task.Factory.StartNew(() => Method1(5, callback));
Task mySecondTask = Task.Factory.StartNew(() => Method2("Hello"));
}
private void Method1(int someNumber, Action<int> intCallback)
{
intCallback(100);
}
private void Method2(string someString)
{
}
You can view Continuation if you do not want to pass callback functions.
source
share