相关疑难解决方法(0)

关于Task.Start(),Task.Run()和Task.Factory.StartNew()的使用

我刚看到3个关于TPL使用的例程,它们执行相同的工作; 这是代码:

public static void Main()
{
    Thread.CurrentThread.Name = "Main";

    // Create a task and supply a user delegate by using a lambda expression. 
    Task taskA = new Task( () => Console.WriteLine("Hello from taskA."));
    // Start the task.
    taskA.Start();

    // Output a message from the calling thread.
    Console.WriteLine("Hello from thread '{0}'.", 
                  Thread.CurrentThread.Name);
    taskA.Wait();
}

public static void Main()
{
    Thread.CurrentThread.Name = "Main";

    // Define and run the task.
    Task taskA = Task.Run( () => Console.WriteLine("Hello from taskA."));

    // Output a …
Run Code Online (Sandbox Code Playgroud)

.net c# task-parallel-library async-await

129
推荐指数
2
解决办法
6万
查看次数

标签 统计

.net ×1

async-await ×1

c# ×1

task-parallel-library ×1