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

前些天出差事情比较少就读了一下《C# Threading Handbook》,感觉还是收获不少。现在写写自己的体会,希望看到更好的评论,抛砖引玉吧。
该书内容涉及广泛,我只写一些自己认为重要但是自己以前不知道的地方吧。

1、线程的生命周期
      System.Threading.Thread类提供了我们start,stop,suspend,resume,join,abort线程的方法。可以通过System.Threading.ThreadState属性来查看线程的状态。
r_未命名.JPG

     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.

转载于:https://www.cnblogs.com/mancini/archive/2005/11/14/276047.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值