📄 module1.vb
字号:
Imports System
Imports System.Threading
Module Module1
Sub Main()
'输出当前时间
Dim nowTime As DateTime
nowTime = nowTime.Now
Console.WriteLine("开始显示时间:" + nowTime.Hour.ToString() + _
":" + nowTime.Minute.ToString() + ":" + _
nowTime.Second.ToString())
Dim mutex1 As Mutex = New Mutex(True)
Dim theClass As class1 = New class1()
Dim WorTCallBack As WaitOrTimerCallback = _
New WaitOrTimerCallback(AddressOf theClass.CallBackMethod)
'主线程拥有这个互斥体
'注册WaitHandler的回调方法
'传递给方法代表的对象参数
'延迟时间为2000毫秒
'周期性地设置定时器
ThreadPool.RegisterWaitForSingleObject( _
mutex1, WorTCallBack, theClass, 2000, False)
'主线程开始等待10秒钟
Thread.Sleep(10000)
Console.WriteLine("按回车键退出程序!")
Console.ReadLine()
End Sub
Public Class class1
Public Sub CallBackMethod(ByVal Obj As Object, ByVal b As Boolean)
'输出当前时间
Dim nowTime As DateTime
nowTime = nowTime.Now
Console.WriteLine(nowTime.Hour.ToString() + ":" + _
nowTime.Minute.ToString() + ":" + _
nowTime.Second.ToString())
End Sub
End Class
End Module
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -