can you please help me understand the difference between the two methods here:
1) why does the first use the thread pool and the second doesn't?
2) Why does the second give you scalability, but the first doesn't - is this related to thread pools?
3) How can I call the two methods in main to make their purpose more obvious (and better high light their differences)?
4) I know async Task methods can be called with await, what about Tasks that lack async like these methods?
public class _12_MyClass
{
public Task SleepAsyncA(int millisecondsTimeout)
{
return Task.Run(() => Thread.Sleep(millisecondsTimeout));
}
public Task SleepAsyncB(int millisecondsTimeout)
{
TaskCompletionSource<bool> tcs = null;
var t = new Timer(delegate { tcs.TrySetResult(true); }, null, -1, -1);
tcs = new TaskCompletionSource<bool>(t);
t.Change(millisecondsTimeout, -1);
return tcs.Task;
}
public static void Main()
{
}
}