Hello group!

I've created a short program to open an application at a specific time. It's working but is attempting to open the application multiple times. What should I be doing to control the number of times it is opening? It only needs to open one time.

Here's my code:

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Label7.Text = TimeOfDay
        If TimeOfDay = "12:02:00 AM" Then
            Process.Start("C:\Program Files (x86)\TestProgram\ftw.exe")
        End If
End Sub

How do I fix this? Any thoughts?

FYI... I'm using Visual Studio 2010/Visual Basic.net

In advance, thanks for the help!

Don Wilson

What you need to do is stop the timer bellow your expression of opening a program

 Timer1.Stop()

This will stop timer from ticking

Or maybe

If DateTime.Now.TimeOfDay = "12:02:00 AM" Then...

However I did not test that and am only really guessing.

Check for something like this:

Dim Name As Process() = Process.GetProcessesByName("myProccess")

Now check if the array Name contains something.
If it does your process is running and doesn't have to be started again.

Ok I've just tested this and got the solution,
Firstly start by increasing the timer interval to "1000" then
Secondly add the Stop call to your code as I've told you on my first post and debug. To play around with this change the interval to 500 and it will open your app twice but when increasing the interval 2x then the timer read once code and stop.

 If TimeOfDay = "08:30:00 AM" Then
 MsgBox("Testing")
 Timer1.Stop()
 End If

Remember to adjust the timers interval on timer properties to 1000.
Hope this answer the question.

@ddanbe what I think is the problem here is the he is using a timer and a timer's interval is in its default values which result in it to execute more then one time, I noticed this when I've applied a Stop call below the MgsBox so that it will display the message and stop but it displayed more then one message before stopping so what I did was that I adjusted the interval to give it enough time to fire perform the task because when you give the timer enough time to pass it can read codes correctly and fire events in a correct way.

The smaller interval value is supplied the more repetition of events. The higher the values the less repetition of events.

Mr. M, I changed the interval to 1000 as suggested. BINGO! That did the trick!!

By the way... I did not insert the "Timer1.Stop" code. Truthfully, I didn't want to do that. As this program developes further, I'm going to add some different tasks to it that will run at various times. Thus it needs to continue to run.

Thanks again for my lesson of the day! You've been of great help! Now on to the next issue!

This question has already been answered. Start a new discussion instead.