第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關(guān)于Task.Start(),Task.Run()和Task.Factory.StartNew()

關(guān)于Task.Start(),Task.Run()和Task.Factory.StartNew()

富國滬深 2019-08-30 16:02:34
我剛看到3個關(guān)于TPL使用的例程,它們執(zhí)行相同的工作; 這是代碼: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 message from the calling thread.    Console.WriteLine("Hello from thread '{0}'.",                       Thread.CurrentThread.Name);    taskA.Wait();}public static void Main(){    Thread.CurrentThread.Name = "Main";    // Better: Create and start the task in one operation.     Task taskA = Task.Factory.StartNew(() => Console.WriteLine("Hello from taskA."));    // Output a message from the calling thread.    Console.WriteLine("Hello from thread '{0}'.",                     Thread.CurrentThread.Name);    taskA.Wait();                  }我只是不明白為什么MS給出了三種不同的方式在運行第三方物流工作,因為他們所有的工作一樣的:Task.Start(),Task.Run()和Task.Factory.StartNew()。告訴我,是Task.Start(),Task.Run()并且Task.Factory.StartNew()所有用于同一目的或者它們有不同的意義嗎?應(yīng)該Task.Start()何時使用,何時應(yīng)該使用Task.Run()何時使用Task.Factory.StartNew()?請幫助我通過示例非常詳細(xì)地了解它們的實際用法,謝謝。
查看完整描述

2 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗 獲得超11個贊

你說“不要創(chuàng)建一個任務(wù)并調(diào)用Start()”將我重定向到任何可能由Task.Start()引起的好的寫入。我需要細(xì)節(jié),因為你說要避免它。謝謝你的答復(fù)。

查看完整回答
反對 回復(fù) 2019-08-30
  • 2 回答
  • 0 關(guān)注
  • 4923 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號