what's the best way to call a normal method in async way?
Just have a normal method like
void DosomethingLong()
What's the best way to ca开发者_如何学编程ll it in an async way?
The standard way is to create a delegate of the method:
Action myMethod = DosomethingLong;
then execute it asynchronously using the APM (example):
IAsyncResult result = myMethod.BeginInvoke(..., null);
// ...
myMethod.EndInvoke(result);
There are other methods you can use; using a Thread, using BackgroundWorker, etc, depending on your exact requirements.
If using .NET 4 you could do
var yourLongRunningTask = Task.Factory.StartNew(DosomethingLong);
// some time later
Task.WaitAll(yourLongRunningTask);
精彩评论