473,774 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service not working after timer is Elapsed

88 New Member
hi all...i have a web service with a timer which has an Elapsed time of 1second(code should get executed for every second).....wit h the following code.....its running perfectly for the first time and has a problem during the next second...the code under "onelapsedt ime" is getting executed.....

public partial class Service1 : ServiceBase
{
Timer timer1 = new Timer();
SqlConnection cn = new SqlConnection(" Server=localhos t;Database=xyz; Integrated Security=false; User Id=x;Password=y ;");
SqlConnection cn1 = new SqlConnection(" Server=localhos t;Database=xyz; Integrated Security=false; User Id=x;Password=y ;");

public Service1()
{
InitializeCompo nent();
}

protected override void OnStart(string[] args)
{
this.timer1.Ena bled = true;
this.Call_Me();

timer1.Elapsed += new ElapsedEventHan dler(OnElapsedT ime);
timer1.Interval = 1000;
timer1.Enabled = true;
}

protected override void OnStop()
{
this.timer1.Ena bled = false;
}

private void Call_Me()
{
SqlCommand command = null;
SqlDataReader reader = null;
string curdate = TimeZone.Curren tTimeZone.ToUni versalTime(Date Time.Now).AddHo urs(-5).ToString();
try
{
cn.Open();
command = new SqlCommand("sel ect p.project_id,n. entered_date,n. record_id,n.not e_id from project AS p INNER JOIN notes as n on p.project_id=n. project_id where p.status_id=10 and n.note_id in(select max(note_id) from notes group by project_id) order by 1", cn);
reader = command.Execute Reader();
while (reader.Read())
{
TimeSpan span = Convert.ToDateT ime(curdate).Su btract(Convert. ToDateTime(read er[1]));
//code to send emails exactly after 2days..
if (span.Days * 24 * 60 * 60 + span.Hours * 60 * 60 + span.Minutes * 60 + span.Seconds >= 172800 && reader[2].ToString() == "")
{
Sending_Mails(C onvert.ToInt32( reader[0]));
Status_Change(1 , Convert.ToInt32 (reader[3]));
}
else if (span.Days * 24 * 60 * 60 + span.Hours * 60 * 60 + span.Minutes * 60 + span.Seconds >= 259200 && reader[2].ToString() == "1")
{
//code to automatically change the ticket status after 3days..
command = new SqlCommand("upd ate project set completed_date ='" + Convert.ToDateT ime(curdate) + "' ,status_id=6 where project_id='" + reader[0] + "'", cn1);
cn1.Open();
command.Execute NonQuery();
cn1.Close();
Status_Change(2 , Convert.ToInt32 (reader[3]));
}
}
reader.Close();
}
catch (Exception ex)
{
System.Diagnost ics.Debug.Write Line(ex.Message );
}
finally
{
command.Dispose ();
cn.Dispose();
}
}

private void OnElapsedTime(o bject source, ElapsedEventArg s e)
{
this.Call_Me();
}

private void Sending_Mails(i nt project_id)
{
some code here...
}

private void Status_Change(i nt i,int j)
{
some code here...
}


Can anyone help me out.......any help wud be appreciated....
Feb 28 '08 #1
0 1287

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2804
by: Derek Wolf | last post by:
I am having some difficulties implementing an UnHandledException handler for the AppDomain.UnhandledException event in a windows service for unhandled exceptions that occur on a System.Timers.Timer elapsed event thread. I have just a few questions concerning the AppDomain.UnhandledException event. I have been to get my unhandledException handler to work correctly when I generate an exception on the main service thread. However, my...
5
2362
by: Eric | last post by:
Hi I built a service that watch file in a directory. I use a simple filewatcher and add a handler to do something when a file is created. I have the following problem. I can build it, I can install it, I can start it but when I start it I have a message that the service is stop because it does nothing and it doesn't execute the code in the service. Please if you have any idea it will be appreciate Thanks yo
6
3460
by: acool | last post by:
I managed to get my VB.NET service installed. Now I can't get it to do anything. Tell me how do you debug smething like this if you have to manually install the assembly to run it? the same code works just fine in a VB form but when I initiallize with the WS OnStart event I get nothing. Any help is greatly appreciated. TB
7
1811
by: Doug Stiers | last post by:
I have a VB app that I'm installing as a Windows Service. I want a subroutine in the app to run every 30 minutes during business hours. How do I do this in VB? I set the startup type as automatic so it's always running. Is there some kind of timer event I can use? Thanks, Doug
4
5621
by: Groundskeeper | last post by:
I can't seem to get a custom UnhandledException handler working for a Windows Service I'm writing in VB.NET. I've read the MSDN and tried various different placements of the AddHandler call, to no avail. Here's the code I'm using, all of which is in the main service class: Protected Overrides Sub OnStart(ByVal args() As String) AddHandler AppDomain.CurrentDomain.UnhandledException, _
1
3957
by: Manuel | last post by:
Used VS2005 to create a windows service and I can't make a timer trigger the tick/elapsed event. On the form viewer I dragged a timer from the components section of the toolbar, enabled it but the tick event does not fire! I tried this other method but the elapsed event does not fire. ---------- Private WithEvents MyTmr As New System.Timers.Timer(1000) Private Sub MyTmr_Elapsed(ByVal sender As Object, ByVal e As
5
10593
by: eb65 | last post by:
I have a need to write a Windows Service application in VB.Net that needs to continuously do some processing, wait ten minutes, then repeat. What is a good approach to coding this type of thing? Basically, I want something like: While True -- do some processing -- sleep 10 minutes
2
2460
by: Trevor | last post by:
Argh! This problem is driving me nuts! Can you help? In November of 2003, I installed a web service on Windows Server 2003 built in VB.NET for v1.1.4322 of the framework. It contains a timer (System.Timers.Timer) which has an interval of 24 hours. Actually, it reads a time like 2AM out of the config file, and calculates the time between the start of the service to 2AM, and sets the timer. When the timer expires, it re-reads the...
5
3307
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
9
2191
by: brendan_gallagher_2001 | last post by:
Hi I am seeing some strange behaviour on a windows (vb.net 1.1) service. Basically, what I see happening is that when the Timer1_Elapsed event fires, it attempts to execute Timer1.Stop() but takes a long time to do this. In the meantime, the Timer1_Elapsed event fires again and a new thread seems to try and also tries to execute Timer1.Stop(). Eventually, both threads manage to execute Timer1.Stop() and both threads execute the...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.