Tick ​​timer handler not working

I am completely new to VB.net and I am trying to run a welterweight script that checks if certain files are open. When it opens first, it checks one specific program, then it will continue to check another program on a timer. However; when I run the code, Sub Timer1 never starts, I have to run it 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 that I already have. my sub timer either does not work or is not checked every 20 seconds. Any ideas?

+5
source share
1 answer

Common errors with timers:

  • You need to run it using the timer.enabled or timer.start function.

  • reset , . ( , system.timers.timer system.threading.timer, .)

  • , , , .

  • , , system.threading.thread.sleep, .

+3

All Articles