• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

[C# Threading Handbook]笔记之一:Threading in .Net

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

前些天出差事情比较少就读了一下《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.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#本地txt文件读取至comboBox下拉列表发布时间:2022-07-13
下一篇:
C#窗体贴边自动隐藏组件ByRed_angelX发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap