Windows Service , fire event at a specific time

Hello All-

 I have been reading about the System.Timers , and I have been able to build some apps that will fire at given intervals ( i.e. every hour, day , etc )

But how can I fire an event at a specific time? Would it be possible that the application could be firing at specified intervals, and then at a specific time, stop execution of the interval events and fire another event?


Any and all help is most appreciated..
Thanks


 Dim t As New System.Timers.Timer()


        Private Sub Form1_Load(ByVal sender As Object, _
               ByVal e As System.EventArgs) Handles MyBase.Load

            AddHandler t.Elapsed, AddressOf TimerFired
            t.Interval = New TimeSpan(0, 1, 0, 0, 0).TotalMilliseconds


            ' Would it be possible to fire another event at a specified time?
 
                IF  t.?????? = 3 AM  THEN
                       STOP FIRST PROCESS

                                   FIRE SECOND EVENT

                       START FIRST PROCESS AGAIN
                END IF





        End Sub


        Private Sub btnStart_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnStart.Click

            t.Enabled = True
            Label1.Text = "Process Started"
        End Sub

        Private Sub btnStop_Click(ByVal sender As System.Object, _
             ByVal e As System.EventArgs) Handles btnStop.Click

 
               t.Enabled = False
                Label1.Text = "Process Stopped"

         
        End Sub

        Public Sub TimerFired(ByVal sender As Object, _
             ByVal e As System.Timers.ElapsedEventArgs)

            Label1.Text = "Last Fired At  " & e.SignalTime.ToString
            ' Perform events here
            PerformMyStuff()


        End Sub

 
drakumAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

iboutchkineCommented:
Why not to put your application on the scheduler?
0
NetPointerCommented:
u can create a batch file which handles your application stop start etc..and put that batch file under windows task scheduler to run at a specific time.
0
GoodJunCommented:
dim yourDate as Date
yourDate=cdate(text.encoding.ascii.getString("11/11/2003 3:00:00")) 'double check the format of date, I am not very confortable with it.

if yourDate.Subtract(Now).totalMilliseconds=0 then

end if
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

UberDeveloperCommented:
i'm not sure about this but would the above code have to fire every millisecond to work?   I was gonna say to make it:

If yourDate = Now then
...
end if

but then that code would have to fire every second to work wouldn't it?

0
UberDeveloperCommented:
maybe you can work off of this....This code works for me just set the 2:18 PM to anything you want

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer2.Enabled = True
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim yourDate As String
        yourDate = Now.TimeOfDay.ToString
        If yourDate.CompareTo("2:18 PM") Then
            MsgBox("Good Work")
            Timer2.Enabled = False
        End If
    End Sub
0
UberDeveloperCommented:
Crap...nevermind it doesn't work   :(


Might give you something to go on though.
0
drakumAuthor Commented:
I appreciate all the help so far ( it has given me some things to look at )

My thinking is that I have installed countless apps/services (which Im sure we all have), and most of them have an update option that allows you to set the update at a specific time..

They are not using the TS to automate the updating.. So I assume that in the logic of the application they have a timer event which will fire when the System.NOW (or whatever it is) = Config Date/Time

Thanks again for all your help so far.. no wonder everyone likes this place so much!
0
UberDeveloperCommented:
ok this one does work....There HAS to be a better way to do this but I just opened a new project put a textbox and timer control on the form and then add the code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer2.Enabled = True
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim yourDate As String
        yourDate = Now.TimeOfDay.ToString.Substring(0, 8)
        TextBox1.Text = Now.TimeOfDay.ToString.Substring(0, 8)

        If yourDate.Equals("14:43:00") Then
            MsgBox("Good Work")
            Timer2.Enabled = False
        End If
    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UberDeveloperCommented:
oh and for some reason "Now.TimeOfDay.ToString.SubString(0, 8) returns military time but I think that might be better cause then you won't have to worry about AM, PM

To test this just set the "14:43:00" to the current time plus one minute and then run the app...when the clock in the textbox clicks over to the time you set the msgbox will be displayed.
0
UberDeveloperCommented:
Oh and one last thing...just take out the Timer2.Enabled = False so it will run everyday
0
drakumAuthor Commented:
Damn... you are UBER.. :)
 Thanks so much.. if there is a better way.. I havent found it .. Ive looked all over and this is the only place where I have been able to find an answer.

 Thanks alot to everyone who replied.. this was driving me crazy

 
0
UberDeveloperCommented:
Thanks alot...one thing you might like to know.  The reason i have the .Substring(0,8) at the end of the yourDate line is because  

Now.TimeOfDay.ToString           returns   14:43:00.XXXXXXX

The x's are (I'm assuming) the seconds elapsed since midnight or something so I just cut it out.

0
drakumAuthor Commented:
Thanks for the followup explanation.. :)

 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.