Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

Windows Service with Windows Timer control doesn't tick

Aug 1 2011 10:11AM by Manas Ranjan Dash   

While designing a windows service if you are planning to use a timer control, make sure not use the System.Windows.Forms.Timer. The timer event will not tick. You have to use the System.Timers.Timer , which will work properly. I came to know about this after developing a windows service using the timer control. Also System.Threading might help, thoguh I have not tried this. private static System.Timers.Timer tmr;

    public AlertService()
    {
        InitializeComponent();
        tmr = new System.Timers.Timer(30* 60000);
    }

    protected override void OnStart(string[] args)
    {
        try
        {
            //Attach the elaspsed event of the timer
            //Set the interval of timer to 30 minute and enable the timer.

            tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed);
            tmr.Interval = 30* 60000;
            tmr.Enabled = true;
        }
        catch (Exception eg)
        {
             //your log
         }
    }
Read More..   [32134 clicks]

Published under: Microsoft .NET Tips ·  ·  ·  · 


Manas Ranjan Dash
39 · 5% · 1484
3
 
1
 
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

3  Comments  

  • Good one manas... But never experienced this problem myself as i always took code from google or my previous projects... :)

    commented on Aug 1 2011 10:14AM
    Ramireddy
    2 · 40% · 12972
  • Possible reason - Windows.Forms.Timer depends on UI Pumps and that is not available here. Ideally it should work and I'll get it checked.

    commented on Aug 2 2011 12:14AM
    Sanket Shah
    306 · 0% · 142
  • Please share with us if you are able to use that, this will help. UI Pump is the reason even i am aware of that.

    commented on Aug 2 2011 4:25AM
    Manas Ranjan Dash
    39 · 5% · 1484

Your Comment


Sign Up or Login to post a comment.

"Windows Service with Windows Timer control doesn't tick" rated 5 out of 5 by 3 readers
Windows Service with Windows Timer control doesn't tick , 5.0 out of 5 based on 3 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]