- 浏览: 6877825 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
逐客叫我:
看完了懵了,一会原生方法栈一会堆,自己都不用一套。
深入JVM系列(一)之内存模型与内存分配 -
xhwahaha:
import java.util.Arrays;public ...
腾讯的一个面试题 -
j00131120:
总结的非常不错
从员工到总监,你要明白的8个道理 -
Will.Du:
这是thinking in java的例子吧
对象序列化 -
ping22changxin:
能否借你事例源码学习一下,谢谢了:812185421@qq.c ...
ActiveMQ发送ObjectMessage的一个问题
如果要求线程按照规定的时间间隔周期性地执行的话,可以使用Timer类将需要调用的方法加入队列等待周期性执行。Timer类包含在System.Threading命名空间。Timer类通过系统提供的线程池线程在每次计时器期满时运行计时器委托。因为System.Threading.Timer对象是在单独的线程中执行,因此在退出应用程序之前需要完全终止计时器。
.NET Compact Framework中的其他Timer类,比如System.Windows.Forms命名空间的Timer类与System.Threading命名空间的Timer类有所不同。System.Windows.Forms.Timer类每次计时器期满时产生WM_TIMER系统消息来触发事件,不能使用单独的线程来执行。System.Windows.Forms.Timer类使用简单且适合用于周期性的更新用户界面。如果需要高精度的计时器,则应该使用System.Threading.Timer。
图23-3展示了使用不同Timer类的精确程度比较。在如图23-3所示的应用程序中分别创建了System.Threading.Timer和System.Windows.Forms.Timer实例,并设置时间间隔为100毫秒。
<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1028" style="WIDTH: 155.25pt; HEIGHT: 207pt" type="#_x0000_t75"><imagedata o:title="" src="file:///D:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image001.png"></imagedata></shape>
图23-3:不同Timer类的精确性比较
这个TimerDemo应用程序测量不同Timer类的平均时间间隔。当点击“模拟界面操作”按钮时,应用程序产生一个额外的处理活动,使不同Timer类在行为上的差别更加清晰明显。Windows.Forms.Timer对象从消息队列接收到一个WM_TIMER消息时调用它自己的委托。Windows.Forms.Timer是单线程组件,精度限定为55毫秒。当应用程序处理繁忙时,时间间隔小于55毫秒的WM_TIMER消息会被忽略。换句话说,由于Windows.Forms.Timer的精度限制,消息队列中不能存在超过一个未处理的WM_TIMER消息,否则多余的WM_TIMER消息会重叠合并,因而丢失计时信号。而在图23-3中正确的做法是,Threading.Timer对象运行在一个单独的线程中,计时器的间隔时间一到则随时被运行。Threading.Timer对象负责处理精确度(两个Timer类的处理次数),因为“模拟界面操作”按钮被点击后,主线程的优先级被临时降低,以此模拟应用程序处于繁忙状态。清单23-7说明了TimerDemo应用程序的实现代码。
清单23-7:TimerDemo应用程序实现代码
<group id="_x0000_s1032" style="WIDTH: 414pt; HEIGHT: 460.2pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line" coordsize="7200,8022" coordorigin="2526,7642" editas="canvas"><lock aspectratio="t" v:ext="edit"></lock><shape id="_x0000_s1033" style="LEFT: 2526px; WIDTH: 7200px; POSITION: absolute; TOP: 7642px; HEIGHT: 8022px" o:preferrelative="f" type="#_x0000_t75"><font size="3"><fill o:detectmouseclick="t"></fill><path o:connecttype="none" o:extrusionok="t"></path><lock v:ext="edit" text="t"></lock></font></shape><rect id="_x0000_s1034" style="LEFT: 2526px; WIDTH: 7200px; POSITION: absolute; TOP: 7642px; HEIGHT: 8022px" strokecolor="#eaeaea" fillcolor="#eaeaea"><textbox style="mso-next-textbox: #_x0000_s1034"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">Public Class TimerDemo<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><p><font face="Times New Roman"></font></p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>Private threadingTimer As Threading.Timer<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>Private prevTimerTicks As Long<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>Private avgTimerTicks As Long<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>Private numTimerExpirations As Long<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>Private timerRunning As Boolean = False<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><p><font face="Times New Roman"></font></p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>Private Sub btnThreadingTimer_Click(ByVal sender As System.Object, _<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">ByVal e As System.EventArgs) Handles btnThreadingTimer.Click<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">If timerRunning = True Then<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">timerRunning = False<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">While Not threadingTimer Is Nothing<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 63pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">Threading.Thread.Sleep(0)<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">End While<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">avgTimerTicks = avgTimerTicks / numTimerExpirations<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>lThreadingTimer.Text = "Avg. Timer Interval: " + avgTimerTicks.ToString() + _<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 63pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">" ms (" + numTimerExpirations.ToString() + ")"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnThreadingTimer.Text = "Start Threading Timer"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnFormsTimer.Enabled = True<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"></span><span style="mso-tab-count: 1"> </span>Else<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>timerRunning = True<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>lThreadingTimer.Text = "Timer running"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnThreadingTimer.Text = "Stop Threading Timer"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnFormsTimer.Enabled = False<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>avgTimerTicks = 0<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>numTimerExpirations = 0<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>prevTimerTicks = Environment.TickCount<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>threadingTimer = New Threading.Timer(New _<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 63pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">Threading.TimerCallback(AddressOf ThreadingTimerTick), Nothing, 0, 100)<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>End If<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span>End Sub<p></p></font></span></p> </div> </td> </tr></tbody></table></textbox></rect><wrap type="none"></wrap><anchorlock></anchorlock></group>
<group id="_x0000_s1029" style="WIDTH: 414pt; HEIGHT: 624pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line" coordsize="7200,10877" coordorigin="2526,7642" editas="canvas"><lock aspectratio="t" v:ext="edit"></lock><shape id="_x0000_s1030" style="LEFT: 2526px; WIDTH: 7200px; POSITION: absolute; TOP: 7642px; HEIGHT: 10877px" o:preferrelative="f" type="#_x0000_t75"><font size="3"><font face="Times New Roman"><fill o:detectmouseclick="t"></fill><path o:connecttype="none" o:extrusionok="t"></path><lock v:ext="edit" text="t"></lock></font></font></shape><rect id="_x0000_s1031" style="LEFT: 2526px; WIDTH: 7200px; POSITION: absolute; TOP: 7642px; HEIGHT: 10877px" strokecolor="#eaeaea" fillcolor="#eaeaea"><textbox style="mso-next-textbox: #_x0000_s1031"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">Private Sub btnFormsTimer_Click(ByVal sender As System.Object, _<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">ByVal e As System.EventArgs) Handles btnFormsTimer.Click<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">If timerRunning = True Then<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">timerRunning = False<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><p><font face="Times New Roman"></font></p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>avgTimerTicks = avgTimerTicks / numTimerExpirations<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>lFormsTimer.Text = "Avg. Timer Interval: " + avgTimerTicks.ToString() + _<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 63pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">" ms (" + numTimerExpirations.ToString() + ")"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnFormsTimer.Text = "Start Forms Timer"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnThreadingTimer.Enabled = True<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Else<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>timerRunning = True<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>lFormsTimer.Text = "Timer running"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnFormsTimer.Text = "Stop Forms Timer"<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnThreadingTimer.Enabled = False<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>avgTimerTicks = 0<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>numTimerExpirations = 0<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>prevTimerTicks = Environment.TickCount<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>formsTimer.Interval = 100<span style="mso-spacerun: yes"> </span>' </font></span><span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">利用窗体上放置的</span><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">Timer</font></span><span style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件</span><span lang="EN-US" style="FONT-SIZE: 9pt"><p></p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>formsTimer.Enabled = True<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>End If<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">End Sub<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><p><font face="Times New Roman"></font></p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">Private Sub btnProcessing_Click(ByVal sender As System.Object, _<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">ByVal e As System.EventArgs) Handles btnProcessing.Click<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnProcessing.Enabled = False<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.BelowNormal<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>For i As Long = 0 To 5000000<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Next<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>btnProcessing.Enabled = True<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.Normal<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"></span>End Sub<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><p><font face="Times New Roman"></font></p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"></span>Private Sub ThreadingTimerTick(ByVal state As Object)<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>If timerRunning = False Then<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>threadingTimer.Dispose()<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>threadingTimer = Nothing<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Else<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Dim currentTimerTicks As Long = Environment.TickCount<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>avgTimerTicks = avgTimerTicks + (currentTimerTicks - prevTimerTicks)<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>numTimerExpirations = numTimerExpirations + 1<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>prevTimerTicks = currentTimerTicks<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>End If<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 14pt; mso-line-height-rule: exactly"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"></span>End Sub<p></p></font></span></p> </div> </td> </tr></tbody></table></textbox></rect><wrap type="none"></wrap><anchorlock></anchorlock></group>
<group id="_x0000_s1026" style="WIDTH: 414pt; HEIGHT: 226.2pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line" coordsize="7200,3943" coordorigin="2526,7642" editas="canvas"><lock aspectratio="t" v:ext="edit"></lock><shape id="_x0000_s1027" style="LEFT: 2526px; WIDTH: 7200px; POSITION: absolute; TOP: 7642px; HEIGHT: 3943px" o:preferrelative="f" type="#_x0000_t75"><font size="3"><font face="Times New Roman"><fill o:detectmouseclick="t"></fill><path o:connecttype="none" o:extrusionok="t"></path><lock v:ext="edit" text="t"></lock></font></font></shape><rect id="_x0000_s1028" style="LEFT: 2526px; WIDTH: 7200px; POSITION: absolute; TOP: 7642px; HEIGHT: 3943px" strokecolor="#eaeaea" fillcolor="#eaeaea"><textbox style="mso-next-textbox: #_x0000_s1028"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">Private Sub formsTimer_Tick(ByVal sender As System.Object, _<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">ByVal e As System.EventArgs) Handles formsTimer.Tick<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">If timerRunning = False Then<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: 21pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">formsTimer.Enabled = False<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>formsTimer = Nothing<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Else<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>Dim currentTimerTicks As Long = Environment.TickCount<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>avgTimerTicks = avgTimerTicks + (currentTimerTicks - prevTimerTicks)<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>numTimerExpirations = numTimerExpirations + 1<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>prevTimerTicks = currentTimerTicks<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"> </span>End If<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 1"></span>End Sub<p></p></font></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><p><font face="Times New Roman"></font></p></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="FONT-SIZE: 9pt"><font face="Times New Roman">End Class<p></p></font></span></p> </div> </td> </tr></tbody></table></textbox></rect><wrap type="none"></wrap><anchorlock></anchorlock></group>
相关推荐
.NET Compact Framework 3.5是微软为嵌入式设备和移动平台开发的一款框架,它使得开发者能够利用C#、Visual Basic .NET或C++等语言创建功能丰富的应用程序。这个框架是.NET Framework在移动设备上的一个精简版,旨在...
《M2Mqtt.NetCF39.dll:MQTT协议与嵌入式开发的融合》 在物联网(IoT)领域,设备之间的通信是至关重要的,而MQTT(Message Queuing Telemetry Transport)作为一种轻量级的发布/订阅消息传输协议,因其高效、可靠...
NetCF(.NET Compact Framework)则是微软开发的一个框架,用于在资源受限的设备上运行.NET应用程序,例如掌上电脑和智能手机。将PrinterCE与NetCF结合,使得开发者可以利用C#的强大编程能力,在嵌入式设备上实现...
总的来说,NetCF2.0插件是Windows CE平台上开发.NET应用程序的关键,它提供了一个完整的框架,使得开发者能够利用熟悉的.NET工具和技术来开发嵌入式和移动应用,极大地扩展了这类设备的功能和应用范围。对于想要涉足...
.NET Compact Framework(NETCF)是微软为嵌入式设备和移动设备开发的一种简化版.NET Framework。这个框架使得开发者能够利用C#等.NET语言在资源有限的设备上构建应用程序,如Windows CE、Windows Mobile设备等。...
VS2005开发的图片按钮控件源代码。可以选择是否显示文字、是否显示边框,文字显示位置等,并可以设置显示图片、按下时显示图片、Disable时显示图片。
2. **C#编程**:作为.NET CF的主要编程语言之一,C#提供了面向对象的特性,如类、接口、继承等,使得开发者能高效地编写代码来控制设备硬件。 3. **设备API访问**:在.NET CF中,访问硬件设备通常需要使用特定的API...
.NET Compact Framework(简称.NET CF)是微软为嵌入式设备,特别是智能手机和平板电脑开发的一个框架,它使得开发者能够利用C#、Visual Basic .NET或C++等.NET语言编写应用程序。此框架是.NET Framework的一个子集...
2. **类库支持**:提供了大量.NET Framework的类库,包括基础类、数据访问、网络通信、图形界面等,方便开发。 3. **语言支持**:支持C#、VB.NET和C++等编程语言,使得开发者能使用熟悉的开发工具进行开发。 4. **...
Barcode Scanners NETCF.msi
标题 "NetCF_2.0\3.5\3.7" 暗示了我们正在讨论的是关于Microsoft .NET Compact Framework的版本信息,这是一个专为嵌入式设备和移动平台设计的.NET框架。这个框架允许开发者使用.NET编程语言(如C#、VB.NET)在这些...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
【使用.NET CF开发Smartphone应用程序】的开发指南 .NET Compact Framework (简称.NET CF)是Microsoft为小型设备如Smartphone和PDA设计的一个轻量级版本的.NET Framework,它允许开发者使用C#或Visual Basic等语言...
".netCF"则是指这个项目是基于.NET Compact Framework开发的。"webbrowser"表示此项目的核心功能是关于网页浏览,而"右键"可能指的是支持在设备上使用右键菜单进行操作,这在桌面环境下常见,但在移动设备上需要特别...
NETCF3.5 NET精简框架3.5版
.NET Compact Framework(简称.NET CF)是微软为嵌入式设备和移动设备开发的应用程序框架,它简化了在这些平台上创建和运行.NET应用程序的过程。本文将深入探讨.NET CF的开发技巧,帮助开发者提升效率并优化应用性能...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
这两个框架是微软开发的用于创建桌面应用和移动设备应用的技术。透明UI允许开发者创建具有视觉吸引力和现代感的界面,其中部分或全部UI元素可以透过显示底层的内容。 在.NET Framework中,透明UI主要通过GDI+...
C#中的Timer类可以用来实现这个定时更新的功能。此外,控件还需要处理文本的布局和绘制,确保滚动过程中的平滑性。这可能涉及到Graphics对象的使用,以及DrawString方法来绘制文本,使用MeasureString方法来计算文本...
WinCE Framewok,3.5版本,适用于wince 6.0系统的手机,gps,手持终端等等