[C# Threading Handbook]筆記之一:Threading in .Net

來源:互聯網
上載者:User

前些天出差事情比較少就讀了一下《C# Threading Handbook》,感覺還是收穫不少。現在寫寫自己的體會,希望看到更好的評論,拋磚引玉吧。
該書內容涉及廣泛,我唯寫一些自己認為重要但是自己以前不知道的地方吧。

1、線程的生命週期
      System.Threading.Thread類提供了我們start,stop,suspend,resume,join,abort線程的方法。可以通過System.Threading.ThreadState屬性來查看線程的狀態。

     The Suspend() method will suspend the current thread indefinitely until another thread wakes it up.
     The effect of calling Join() method is that the thread will be blocked until either the other thread completes or the time period elapses, whichever occurs first.
     The Abort() method would be very useful, if you want to terminate the thread for whatever reason.

2、適合與不適合使用線程地方
      適合使用線程的機會:
      a. Background Processes 
      The first opportunity to spawn a new thread occurs when your application needs to run a large process in the background while still keeping its user interface active and usable.
      b. Accessing external resources
      The second circumstance in which you might want to consider spawning a new thread occurs when you are accessing resources that are not local to your system. 
     不適合多線程的場合:
     The first is an instance where execution order is extremely important, and the second is a mistake seen quite often in code - creating new threads in a loop.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.