2011年6月7日 星期二

AutoResetEvent autoEvent.WaitOne

此組指令,運用在POS的週邊設備會較為妥善!
盡量少用 appliation.doevent 或 sleep 或 timer
底下為範例,看大家怎運用!
----------

Imports System
Imports System.Threading

Public Class Form1
Shared autoEvent As New AutoResetEvent(False)
Dim t1 As Date
Dim t2 As Date

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t1 = Now
TextBox1.Text = ""
Label2.Text = "等待:"
For i As Integer = 0 To 100
TextBox1.Text += i.ToString + vbCrLf
autoEvent.WaitOne(50)
Next
t2 = Now
Label2.Text = "等待:" & (t2 - t1).ToString
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
t1 = Now
TextBox1.Text = ""
Label1.Text = "正常:"
For i As Integer = 0 To 100
TextBox1.Text += i.ToString + vbCrLf
Next
t2 = Now
Label1.Text = "正常:" & (t2 - t1).ToString
End Sub
End Class

沒有留言:

張貼留言