+ Reply to Thread
Results 1 to 6 of 6

Thread: Timer component not working in Service Application

  1. #1
    Programmer smith is an unknown quantity at this point
    Join Date
    Jun 2006
    Posts
    153

    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. #2
    Programming Expert dirkfirst is on a distinguished road
    Join Date
    May 2006
    Posts
    354
    Are you using the standard Timer as in, the timer that you install on form applications?
    DirkFirst

  3. #3
    Lop
    Lop is offline
    Speaks fluent binary Lop has a spectacular aura about Lop has a spectacular aura about Lop's Avatar
    Join Date
    May 2006
    Posts
    1,179
    You can't use the stand GUI timer with a service. Use system.timer or thread.timer to accomplish this.
    Lop

  4. #4
    Programmer smith is an unknown quantity at this point
    Join Date
    Jun 2006
    Posts
    153
    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";
    }

  5. #5
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97
    I've got code that does this. I'll paste it when I go back to work.

  6. #6
    Learning Programmer Cosmet is an unknown quantity at this point
    Join Date
    Oct 2006
    Posts
    58
    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;
            }

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Working with TADO Table
    By MrDiaz in forum Pascal/Delphi
    Replies: 1
    Last Post: 07-27-2009, 05:16 AM
  2. Windows XP Tricks & Tips!!!!..new ones.
    By pranky in forum Tutorials
    Replies: 9
    Last Post: 08-23-2008, 03:22 PM
  3. Introducing The PAD Service Shareware Network
    By pad service in forum Hosting and Registrars
    Replies: 2
    Last Post: 05-16-2006, 02:07 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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