Search This Blog

Tuesday, February 2, 2010

VB2005 Timers

The .NET Framework ထဲမှာ သုံးစရာ timer အမျိုးမျိုး ရှိပါတယ်။ Windows Forms applications တွေမှာ ဆိုရင် System.Windows.Forms.Timer control ကို သုံးနိုင်ပြီး user interface မရှိတဲ့ application မှာ ဆိုရင်တော့ System.Threading.Timer class ဒါမှမဟုတ် the System.Timers.Timer class ကို သုံးနိုင်ပါတယ်။ အောက်မှာ ပြထားတဲ့ နမူနာ မှာ System.Threading.Timer class ကို သုံး ပြီး procedure တစ်ခုကို ခေါ်သုံးထား ပါတယ်။ Timer ကို စပြီးတာ နဲ့ သူ့ရဲ့ တန်ဖိုးတွေကို ပြောင်းချင်ရင် Change method ကိုသုံးပြီးမှ ပြောင်းလို့ ရပါတယ်။ Stop method မရှိပါဘူး။ ရပ်ချင်ရင် Dispose method ကိုသုံးမှ ရပါမယ်။
Imports System.Threading
Dim dueTime as New TimeSpan(0,0,1)
Dim period as New TimeSpan(0,0,0,0,500)
Dim t As New Timer(AddressOf TimerProc, Nothing, dueTime, period)
Dim tEn As Boolean = True
Private Sub TimerProc(ByVal state As Object)
 If tEn = True Then
'Do timer things
 End If
End Sub