【php精品源码栏目提醒】:以下是网学会员为您推荐的php精品源码-【精品】多线程TPnew10 - 其它资料,希望本篇文章对您学习有所帮助。
第十章多线程 ACCP V4.0 回顾调试是搜寻和消除应用程序中的错误的过程语法错误表示编译器无法理解代码调试模式可用来重复编译和排除应用程序中的错误,直至能够成功运行“局部变量”窗口允许用户监控当前程序中所有变量的值单元测试和集成测试是测试大型应用程序的常用技术当应用程序遇到运行时错误时,就会引发异常C 中的所有异常都派生自 Exception 类2 ACCP V4.0 目标理解线程的概念理解.NET中线程的属性和方法创建和使用线程理解线程的特点、优点及使用场合3 ACCP V4.0 线程简介 3-1同时执行所有任务, 操作系统允许计算机时间更少,效率更高 同时执行多项操作 一览无遗 在同一时间点执行各项进程 人 体 读 ,写 编译程序 血液循环 发送/接收邮件 程序 打印文件 (进程) 其他4 ACCP V4.0 线程 1 线程简介 3-2 线程 2 线程 3 程序 1 单独的执行路径 线程 1 线程 2 线程 3 程序 25 ACCP V4.0 线程简介 3-3 在以下情况中可能要使用到多线程: 程序需要同时执行两个或多个任务 程序要等待某事件的发生,例如用户输入、文件操作、 网络操作、搜索等 后台程序6 ACCP V4.0 System.Threading 命名空间 2-1 System.Object System.Delegate System.ValueType System.MulticastDelegate System.Threading.Thread System.Exception System.Threading.ThreadStart System.SystemException System.EnumSystem.Threading. System.Threading. System.Threading. ThreadPriority ThreadState ThreadAbortExcep System.Thread tion StateException 7 ACCP V4.0 System.Threading 命名空间 2-2 System.Delegate System.Object System. MulticastDelegate System.Threading ThreadStart System.ValueType System.Enum ThreadPriority8 ACCP V4.0 Thread 类的属性和方法 2-1 引用System.Threading 命名空间Thread 线程实例名 new Threadnew ThreadStart方法名 运行在线程上的方法 只创建但不启动线程 线程实例名.Start9 ACCP V4.0 Thread 类的属性和方法 2-2 属性 方法静态 CurrentThread Sleep 静态 IsAlive Abort Name Join Priority Resume ThreadState Start Suspend10 ACCP V4.0 线程的生命周期 线程已创建但并未启动 未开始 线程已启动 开始 线程已恢复 在 I/O 操作期间线程被阻止 I/O 操作完成后运行 已开始 恢复 I/O 完成 等待,休眠,加入线程被阻止,另一个操作正在进行 正在运行 提前中断或特地停止线程 暂停 发送 I/O 请求 完成 等待/休眠/加入 已阻止 已暂停 已停止 暂时中断的线程 11 ACCP V4.0class SimpleThreadDemo 示例 static void Mainstring args Thread.CurrentThread.Name “主线程 Thread objThread new Threadnew ThreadStartActionMethod objThread.Name “子线程 //启动子线程 并为该线程执行 ActionMethod objThread.Start 输出结果混乱 //这将为主线程执行 ActionMethod 实例化 objThread 线程并 ActionMethod 开始执行 ActionMethod 将由应用程序线程执行 static void ActionMethod forint count 1 count 4990 forint count1count
上一篇:
【精品】0520source_code_and_tarball
下一篇:
高等数学课程复习资料