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运行时的支持.
推荐阅读
- 零基础转新媒体如何,转行做新媒体需要哪些基础
- c语言zip字符串压缩,c语言解压缩字符串
- 女鞋网红直播卖货,直播卖鞋哪个主播比较出名
- c语言绘制函数图 c语言绘图函数库
- pic接口怎么装显卡,pice插槽
- 如何引用ppt背景图形,ppt引用图片
- 成组拍摄镜头是什么,成组拍摄镜头是什么意思
- python保护函数 python代码保密
- 装机硬盘无法打开怎么办,安装硬盘后电脑无法正常开机