If you use action.BeginInvoke(), you have to call EndInvoke somewhere - else the framework has to hold the result of the async call on the heap, resulting in a memory leak.
If you don't want to jump to C# 5 with the async/await keywords, you can just use the Task Parallels library in .Net 4. It's much, much nicer than using BeginInvoke/EndInvoke, and gives a clean way to fire-and-forget for async jobs:
using System.Threading.Tasks;
...
void Foo(){}
...
new Task(Foo).Start();
If you have methods to call that take parameters, you can use a lambda to simplify the call without having to create delegates:
void Foo2(int x, string y)
{
return;
}
...
new Task(() => { Foo2(42, "life, the universe, and everything");}).Start();
I'm pretty sure (but admittedly not positive) that the C# 5 async/await syntax is just syntactic sugar around the Task library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…