Closed Thread
Results 1 to 6 of 6

Thread: Timer component not working in Service Application

  1. #1
    smith is offline Programmer
    Join Date
    Jun 2006
    Posts
    153
    Rep Power
    0

    Timer component not working in Service Application

    I've added a timer to my C# application which is running as a service. Everything seems to work fine but the timer never ticks! I've tried setting it to various intervals to see if it does work but nothing! I've also added a writelog even in the tick to see if it works or not. It does not.

    Any ideas?
    Code:
    for (int i;;) {
       cout << "Smith";
    }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23
    Are you using the standard Timer as in, the timer that you install on form applications?

  4. #3
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30
    You can't use the stand GUI timer with a service. Use system.timer or thread.timer to accomplish this.

  5. #4
    smith is offline Programmer
    Join Date
    Jun 2006
    Posts
    153
    Rep Power
    0
    How do I use the system.timer or thread.timer? I have no idea how to make it tick.
    Code:
    for (int i;;) {
       cout << "Smith";
    }

  6. #5
    Jordan Guest
    I've got code that does this. I'll paste it when I go back to work.

  7. #6
    Cosmet is offline Learning Programmer
    Join Date
    Oct 2006
    Posts
    58
    Rep Power
    0
    I've got some code as well. Here is how to use it:

    Declare it in your class
    Code:
    public partial class Service1 : ServiceBase
        {
            // Create a threaded timer
            private static System.Timers.Timer t = new System.Timers.Timer();
    If you are doing a timer, you should use a thread that executes a function which then enables the timer. I'll skip that part though.

    In your function:
    Code:
                // Set the interval in MS for the timer
                t.Interval = 30000; // 30 seconds
    
                // TODO: Add code here to start your service.
                //Enable the timer and set the interval for 10 seconds
                t.Enabled = true;
    
                //Assign a new event handler to the Elapsed method
                t.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);
    
                //Start the timer
                t.Start();
    Your Tick Function:
    Code:
            private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
            {
                // Stop the Timer
                t.Stop();
                t.Enabled = false;
    
                // Execute the function
                myFunction();
    
                // Enable the timer
                t.Start();
                t.Enabled = true;
            }

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 11-12-2010, 09:55 AM
  2. Replies: 6
    Last Post: 04-19-2010, 03:40 AM
  3. Topcoder component
    By selvaa89 in forum Java Help
    Replies: 3
    Last Post: 02-07-2010, 09:54 AM
  4. Timer, not working at right pace?
    By Skrubber in forum Visual Basic Programming
    Replies: 11
    Last Post: 11-24-2009, 11:45 PM
  5. Online Web Service Application
    By KeithAVH in forum MarketPlace
    Replies: 2
    Last Post: 10-24-2008, 11:56 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts