[This is preliminary documentation and is subject to change.]
This class allows you to safely invoke a delegate asynchronously, similarly to calling
BeginInvoke(), without ever having to call EndInvoke(). Simply call AsyncHelper.QueueTaskToThreadPool()
| C# | Visual Basic | Visual C++ |
public class AsyncUtils
Public Class AsyncUtils
public ref class AsyncUtils
| All Members | Constructors | Methods | |||
| Icon | Member | Description |
|---|---|---|
| AsyncUtilsAsyncUtilsNew()() | ||
| QueueTaskToThreadPool(Delegate, array<Object>[]()) |
This method allows you to safely invoke a delegate asynchronously, similarly to calling
BeginInvoke(), without ever having to call EndInvoke().
|
Starting with the 1.1 release of the .NET Framework, the SDK docs now carry a caution that mandates calling EndInvoke on delegates you've called BeginInvoke on in order to avoid potential leaks. This means you cannot simply "fire-and-forget" a call to BeginInvoke without the risk of running the risk of causing problems.
For example, assuming a delegate defined as follows:
CopyC#
Instead of doing this to fire-and-forget an async call to some
target method:
CopyC#
You would instead do this:
CopyC#
delegate void CalcAndDisplaySumDelegate( int a, int b );
CalcAndDisplaySumDelegate d = new CalcAndDisplaySumDelegate(someCalc.Add); d.BeginInvoke(2, 3, null);
CalcAndDisplaySumDelegate d = new CalcAndDisplaySumDelegate(someCalc.Add); AsyncHelper.QueueTaskToThreadPool(d, 2, 3);
This code was created from a sample by Mike Woodring( http://staff.develop.com/woodring )
| Object | |
| AsyncUtils | |