摘要: 首先明确什么时候用多线程?多线程是提高cpu的利用率,只有当cpu空闲时间比较多情况下,才能体现出多线程的优势。线程:线程是进程的组成单位。主要步骤:① 实例化ThreadStart对象,参数是线程将要执行的方法。② 编写线程将要执行的方法。③ 实例化Thread对象,参数是刚才实例化ThreadStart的对象。④Thread对象启动,线程的例子:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using Syste 阅读全文
posted @ 2012-08-04 17:19 杨斌_济南 阅读(6834) 评论(0) 推荐(0) 编辑
摘要: (1)首先声明Timer变量://一定要声明成局部变量以保持对Timer的引用,否则会被垃圾收集器回收!private System.Threading.Timer timerClose; (2)在上述自动执行代码后面添加如下Timer实例化代码:// Create a timer thread and start ittimerClose = new System.Threading.Timer(new TimerCallback(timerCall), this, 5000, 0);//Timer构造函数参数说明:Callback:一个 TimerCallback 委托,表示要执行的方法。 阅读全文
posted @ 2012-08-04 10:11 杨斌_济南 阅读(42616) 评论(4) 推荐(2) 编辑