Solved

How to set timer in windows service program?

Posted on 2009-04-08
5
265 Views
Last Modified: 2013-12-17
Hi

I built a windows service program which needs to keep on checking data in mssql db for every minute.

In Modules.Systems.UpdateProcess, there have another 2 functions need to connect to different tables in the same DB.

If I set timer2, timer3 and interval = 360000, will they be crashed? as all 3 objects connect to DB in the same time.  

Modules.Systems.UpdateProcess UP = new Modules.Systems.UpdateProcess();
            this.timer1 = new System.Timers.Timer();
            this.timer1.Interval = 360000; 
            this.timer1.Elapsed += new ElapsedEventHandler(UP.UpdateBalance);

Open in new window

0
Comment
Question by:techques
[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
  • 3
5 Comments
 
LVL 11

Expert Comment

by:bmatumbura
ID: 24096182
I don't see a problem with this. It should connect and query the database fine.
0
 
LVL 11

Expert Comment

by:bmatumbura
ID: 24096191
This is because SQL server can handle multiple connection from the same application or from multiple applications
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24096517
do they use the same connection or different connections ? if they are connectiong to the db using a singleton object then the code will fail
0
 

Author Comment

by:techques
ID: 24098610
Yes, I set different connection, but the problem is the code in 2nd and 3rd timers did not execute.
private System.ComponentModel.IContainer components = null;
 
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            this.eventLog1 = new System.Diagnostics.EventLog();
            ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
            Modules.Systems.Process UP1 = new Modules.Systems.Process();
            Modules.Systems.Process UP2 = new Modules.Systems.Process();
            Modules.Systems.Process UP3 = new Modules.Systems.Process();
 
            this.eventLog1.Log = "Log";
            this.eventLog1.Source = "LogSource";
            this.timer1 = new System.Timers.Timer();
            this.timer1.Interval = 360000; 
            this.timer1.Elapsed += new ElapsedEventHandler(UP1.UpdateClientABalance);
            this.timer2 = new System.Timers.Timer();
            this.timer2.Interval = 360000; 
            this.timer2.Elapsed += new ElapsedEventHandler(UP2.UpdateClientBBalance);
            this.timer3 = new System.Timers.Timer();
            this.timer3.Interval = 360000;
            this.timer3.Elapsed += new ElapsedEventHandler(UP3.UpdateClientCBalance);
 
            ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
            this.ServiceName = "Processing";
 
        }
 
        private System.Timers.Timer timer1;
        private System.Timers.Timer timer2;
        private System.Timers.Timer timer3;
        private System.Diagnostics.EventLog eventLog1;

Open in new window

0
 
LVL 11

Accepted Solution

by:
bmatumbura earned 50 total points
ID: 24098938
Insert the following statements near the end of the InitializeComponent() routine (but before the (System.ComponentModel.ISupportInitialize ...) statement):
this.timer1.start();
this.timer2.start();
this.timer3.start();

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code enhancement 4 34
.NET Enums [Flags] & Bitwise Design Question 6 39
Upgrade code from VS 2010 to VS 2015 7 34
Visual C# Windows Project - Clone Form 4 26
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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