Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows Service , fire event at a specific time

Posted on 2003-11-11
13
Medium Priority
?
627 Views
Last Modified: 2008-02-01
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

 
0
Comment
Question by:drakum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 9724955
Why not to put your application on the scheduler?
0
 
LVL 4

Expert Comment

by:NetPointer
ID: 9725024
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
 
LVL 10

Expert Comment

by:GoodJun
ID: 9725261
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
How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

 
LVL 2

Expert Comment

by:UberDeveloper
ID: 9725627
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
 
LVL 2

Expert Comment

by:UberDeveloper
ID: 9725809
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
 
LVL 2

Expert Comment

by:UberDeveloper
ID: 9725820
Crap...nevermind it doesn't work   :(


Might give you something to go on though.
0
 

Author Comment

by:drakum
ID: 9726009
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
 
LVL 2

Accepted Solution

by:
UberDeveloper earned 2000 total points
ID: 9726011
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
 
LVL 2

Expert Comment

by:UberDeveloper
ID: 9726032
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
 
LVL 2

Expert Comment

by:UberDeveloper
ID: 9726665
Oh and one last thing...just take out the Timer2.Enabled = False so it will run everyday
0
 

Author Comment

by:drakum
ID: 9732051
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
 
LVL 2

Expert Comment

by:UberDeveloper
ID: 9732606
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
 

Author Comment

by:drakum
ID: 9733492
Thanks for the followup explanation.. :)

 
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question