vb.net委托代码 vbnet task( 三 )


System.Threading.Thread.Sleep(1000)
If (True) Then
Dim e As New AlarmEventArgs(_snoozePressed, nrings)
OnAlarm(e)
End If
Else
System.Threading.Thread.Sleep(300)
Dim e As New AlarmEventArgs(_snoozePressed, nrings)
OnAlarm(e)
End If
End If
Loop
End Sub
End Class
' The WakeMeUp class has a method AlarmRang that handles the
' alarm event.
'
Public Class WakeMeUp
Public Sub AlarmRang(sender As Object, e As AlarmEventArgs)
Console.WriteLine((e.AlarmText + ControlChars.Cr))
If Not e.SnoozePressed Then
If e.NumRings Mod 10 = 0 Then
Console.WriteLine(" Let alarm ring? Enter Y")
Console.WriteLine(" Press Snooze? Enter N")
Console.WriteLine(" Stop Alarm? Enter Q")
Dim input As String = Console.ReadLine()
If input.Equals("Y") Or input.Equals("y") Then
Return
Else
If input.Equals("N") Or input.Equals("n") Then
CType(sender, AlarmClock).SnoozePressed = True
Return
Else
CType(sender, AlarmClock).Stop = True
Return
End If
End If
End If
Else
Console.WriteLine(" Let alarm ring? Enter Y")
Console.WriteLine(" Stop Alarm? Enter Q")
Dim input As String = Console.ReadLine()
If input.Equals("Y") Or input.Equals("y") Then
Return
Else
CType(sender, AlarmClock).Stop = True
Return
End If
End If
End Sub
End Class
' The driver class that hooks up the event handling method of
' WakeMeUp to the alarm event of an Alarm object using a delegate.
' In a forms-based application, the driver class is the
' form.
'
Public Class AlarmDriver
Public Shared Sub Main()
' Instantiates the event receiver.
Dim w As New WakeMeUp()
' Instantiates the event source.
Dim clock As New AlarmClock()
' Wires the AlarmRang method to the Alarm event.
AddHandler clock.Alarm, AddressOf w.AlarmRang
clock.Start()
End Sub
End Class
End Namespace
求助vb.net处理多线程的问题,想用委托来做以下代码 。两个button控件和两个textbox控件 。Public Class Form1
Delegate Sub MySubDelegate(ByVal txt As String,ByVal num as integer)
Private Sub txtW(ByVal txt As String,ByVal num as integer)
Dim msgd As New MySubDelegate(AddressOf Me.txtW1)
Me.Invoke(msgd, txt,num)
End Sub
Private Sub txtW1(ByVal txt As String,ByVal num as integer)
if num=1 then
TextBox1.Text=txt
else
TextBox2.Text=txt
end if
End Sub
Dim t1, t2 As Threading.Thread
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub autoAction1()
For i = 0 To 100
Delay(10)
txtw(i.ToString,1)
Next
t1.Abort()
End Sub
Private Sub autoAction2()
For i = 0 To 100
Delay(10)
txtw(i.ToString,2)
Next
t2.Abort()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t1 = New Threading.Thread(AddressOf autoAction1)
t1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
t2 = New Threading.Thread(AddressOf autoAction2)
t2.Start()
End Sub
Public Sub Delay(ByRef Interval As Double)'Interval单位为毫秒
Dim time As DateTime = DateTime.Now
Dim Span As Double = Interval * 10000
While ((DateTime.Now.Ticks - time.Ticks)Span)
Application.DoEvents()
End While
End Sub
End Class
vb6.0和vb.net有什么区别?VB6.0是基于对象的,VB.NET是面向对象的,它们之间的语法上差距还是比较大的.
VB.NET生成的是托管代码,必须运行于.NET框架之上.VB6则依赖于VB6运行时的支持.

推荐阅读