This is the traditional thread creation code:
public static void Ping()
{
new Thread(workThreadPingRequest) { IsBackground = true }.Start();
}
private static void workThreadPingRequest()
{
line1(); //Create connection
line2(); //Ask ping
line3(); //Process the reply and close connection
}
I’ve got many pairs like them. So how can I remove seperate worker thread function to make the code easier -to me- like below:
public static void Ping()
{
new Thread(new Func<void> fn = () =>
{ line1(); line2(); line3();})
{ IsBackground = true }
.Start();
}
Or is it possible?
Have you tried using .NET 4’s Tasks?