最简单的方法做一个火和忘记的方法在c#4.0 [英] Simplest way to do a fire and forget method in c# 4.0
问题描述
我真的很喜欢这个问题:
我只想知道现在我们有并行扩展在C#4.0是有更好的更清洁的方式做火&
使用任务
类是的,但是不要使用平行linq?
PLINQ实际上是用于查询集合。
类似下面的任务将用于任务。
Task.Factory.StartNew(()=> FireAway());
或甚至...
Task.Factory.StartNew(FireAway); new Task(FireAway).Start();
其中 FireAway
是
public static void FireAway()
{
// Blah ...
}
因此,凭借类和方法名称terseness这会跳过线程池版本六个和十九个字符之间, :)
ThreadPool.QueueUserWorkItem(o => FireAway
I really like this question:
Simplest way to do a fire and forget method in C#?
I just want to know that now that we have Parallel extensions in C# 4.0 is there a better cleaner way to do Fire & Forget with Parallel linq?
解决方案 With the Task
class yes, but PLINQ is really for querying over collections.
Something like the following will do it with Task.
Task.Factory.StartNew(() => FireAway());
Or even...
Task.Factory.StartNew(FireAway);
Or...
new Task(FireAway).Start();
Where FireAway
is
public static void FireAway()
{
// Blah...
}
So by virtue of class and method name terseness this beats the threadpool version by between six and nineteen characters depending on the one you choose :)
ThreadPool.QueueUserWorkItem(o => FireAway());
这篇关于最简单的方法做一个火和忘记的方法在c#4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!