计时器未运行的控制台APP [英] Console APP with Timer not running
问题描述
我首先在WinForm项目中进行了此操作,现在将应用程序类型更改为控制台应用程序",删除了form1.vb,将启动对象更改为此"Module1.vb",但是现在我可以没有运行该应用程序.应用程序运行良好,但是计时器刻度没有执行任何操作,代码完全相同,我只更改了 sub main/form1_load 名称
I did this first into a WinForm project, now I've changed the application type to "Console application", I've deleted the form1.vb, changed the startup object to this "Module1.vb" but now I can't run the app. well the app runs but the timer tick is doing nothing, the code is exactly the same, I only did one change for the sub main/form1_load name
我做错了什么?
PS:我已经测试了错误是否是在锁定方法的条件下进行的,并且一切都很好,问题出在股票行情事件中,但我不知道为什么.
PS: I've tested if the error was in the conditional of the lock method and all is good there, the problem is with the ticker event but I don't know why.
#Region " Vars "
Dim Running As Boolean = False
Dim Errors As Boolean = False
Dim Executable_Name As String = Nothing
Dim Toogle_Key As System.Windows.Forms.Keys = Nothing
Dim WithEvents Toogle_Key_Global As Shortcut = Nothing
Dim Executable_Timer As New Timer
Dim Lock_Timer As New Timer
Dim Lock_Interval As Int32 = 10
Dim Lock_Sleep As Int32 = Get_Milliseconds(3)
Dim Screen_Center_X As Int16 = (Screen.PrimaryScreen.Bounds.Width / 2)
Dim Screen_Center_Y As Int16 = (Screen.PrimaryScreen.Bounds.Height / 2)
#End Region
' Load
Sub main()
Pass_Args()
Sleep()
Lock()
End Sub
' Lock
Private Sub Lock()
If Process_Is_Running(Executable_Name) Then
AddHandler Lock_Timer.Tick, AddressOf Lock_Tick
AddHandler Executable_Timer.Tick, AddressOf Executable_Tick
Lock_Timer.Interval = Lock_Interval
Lock_Timer.Start()
Executable_Timer.Start()
Running = True
Else
Terminate()
End If
End Sub
' Lock Tick
Private Sub Lock_Tick()
Console.WriteLine("test")
If Running Then Cursor.Position = New Point(Screen_Center_X, Screen_Center_Y)
End Sub
更新
我像在MSDN的示例中一样进行了这些更改:
I made these changes like in the examples of MSDN:
Dim Executable_Timer As New System.Timers.Timer
Dim Lock_Timer As New System.Timers.Timer
AddHandler Lock_Timer.Elapsed, AddressOf Lock_Tick
AddHandler Executable_Timer.Elapsed, AddressOf Executable_Tick
但是滴答声/过去的时间仍然无济于事...
But the tick/elapsed is still doing nothing...
推荐答案
FROM MSDN
FROM MSDN
实现一个计时器,该计时器以用户定义的时间间隔引发事件.此计时器经过优化,可在Windows Forms应用程序中使用,并且必须在窗口中使用.
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.
您需要一个 System.Timer
当然这需要一个不同的事件处理(示例取自MSDN)
You need a System.Timer
Of course this requires a different event Handling
(Example taken from MSDN)
' Create a timer with a ten second interval.
Dim aTimer = new System.Timers.Timer(10000)
' Hook up the Elapsed event for the timer.
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
....
Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime)
End Sub
这篇关于计时器未运行的控制台APP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!