I'm completely new to VB.net, and I'm trying to run a semi-intermediate script that checks for certain files being open. When it first opens, it checks for one particular program, then it will continue checking for a different program on a timer.. However; when I run the code, the Sub Timer1 never runs, I have it set to run every 20 seconds..
Imports System.Net
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Process.GetProcessesByName("PROGRAM1").Length >= 1) Then
MessageBox.Show("This Client is already running!", "IG Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Environment.Exit(0)
Else
Process.Start(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "program.exe"))
'''' OPEN PROGRAM ABOVE ''''
End If
For Each frm As Form In Application.OpenForms
frm.WindowState = FormWindowState.Minimized
Next frm
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If (Process.GetProcessesByName("PROGRAM2").Length >= 1) Then 'CHECK FOR PROGRAM
MessageBox.Show("Program is running!", "IG Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Environment.Exit(0)
Form3.Show()
Else
MessageBox.Show("Program is not running!")
End If
End Sub
End Class
Above is the code I already have.. my timer sub either isn't running or isn't checking every 20 seconds. Any ideas?
Common mistakes with timers are:
You need to start it with either timer.enabled or timer.start.
You might need to reset the timer in the tick handler, depending on the type of timer and property settings. (There is the timer control, system.timers.timer, and system.threading.timer, each of which is a little different.)
You might need to disable temporarily it in the tick handler to make sure it doesn't re-enter the handler and cause problems.
If you need to wait while a timer is running, it is MUCH better to use system.threading.thread.sleep rather than a loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With