惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
D
Docker
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
月光博客
月光博客
小众软件
小众软件
量子位
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
博客园 - 叶小钗
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
C
Check Point Blog

博客园 - 左佩玉

通过了 70-316 考试 .NET SDK 工具 进程 程序配置 程序集 全局化和本地化 实现帮助 可访问性设计 访问和调用外部组件 实现打印 自定义控件 使用 GDI+ 在ADO.net 中使用xml 绑定、查看和筛选数据 ADO.net 处理和抛出异常 使用Debug和Trace 测试和调试 继承 System.Collections.CollectionBase 创建一个强类型集合类
线程
左佩玉 · 2005-08-27 · via 博客园 - 左佩玉

System.Threading

创建线程代理
ThreadStart threadFunc;
MyClass myObject = new MyClass();
threadFunc = new ThreadStart(myObject.Func1);

创建线程对象
Thread thread1 = new Thread(threadFunc);

合并
MyClass myObject = new MyClass();
Thread thread1 = new Thread(new ThreadStart( myObject.Func1 ));

启动线程
thread1.Start();

使主线程睡眠
Thread.Sleep(1000);

挂起
thread1.Suspend();

恢复
thread1.Resume();

终止线程
thread1.Abort();

使调用线程一直处于等待状态直到被调用线程结束
thread1.Join();
设置等待时间
  if  (thread1.Join(1000) == true)
  {
     //被等待线程已结束
   }
   else
  {
     //被等待线程没结束
   }   

线程之间的同步
Monitor.Enter(myObject);
....//可在此用 Monitor.Pulse(myObject); 释放指定对象上的同步锁,转入就绪队列 
    //Monitor.PulseAll(myObject);
Monitor.Exit(myObject);

指定时间获取同步锁,不会被堵塞
Monitor.TryEnter(myObject, 10000);

Monitor.TryEnter(myObject, Timeout.Infinite);

释放同步锁,线程进入等待
Monitor.Wait(myObject);
Monitor.Wait(myObject,1000);