I would like to use the async/await in C# 4.0 and I have installed the following package:
http://www.nuget.org/packages/Microsoft.Bcl.Async/
The problem is t
using System.Threading.Tasks;
private void simpleMethod()
{
var tsk = Task.Factory.StartNew(() => DoSomeWorkAsync());
Task.WaitAll(tsk);
DataTable table = tsk.Result;
}
It is important that the asynchronous method should not contain any method that affects form controls
private DataTable DoSomeWorkAsync()
{
System.Data.DataTable table = new System.Data.DataTable();
Thread.Sleep(4000); // Any long time process
return table;
}
More information: https://www.simplethread.com/net-40-and-systemthreadingtasks/