module1.vb

来自「适合VB初学者看」· VB 代码 · 共 39 行

VB
39
字号
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 + =
减小字号Ctrl + -
显示快捷键?