在线程中运行代码

时间:2014-02-14 06:12:51

标签: c# multithreading c#-4.0

在c#4中,如何在单独的线程中运行一段代码?

我只想在不影响主线程的情况下执行“保存到最近使用过的”。

2 个答案:

答案 0 :(得分:4)

使用Task

类,

Task.Run(() => Console.WriteLine("I'm executing on the threadpool"));

答案 1 :(得分:2)

这样的事情:

Task.Factory.StartNew(() => { 
    //What ever code you like...
});