473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

windows service

Hi I have a service which has to be send an email every tuesday and friday. what i did is i created a timer control like this

Timer _timer = new Timer();
while initializing..............
_timer = new Timer(89000000);
in start event ...............
_timer.Start();

now i call a class in start function and this class takes todays date, checks if it is tuesday or friday and does what ever it has to do.

my problem is if today is tuesday and i start the servce it emails the file but when it is friday it has to do the same thing but it doesn't. i have to stop and start the service. Again on tuesday i have to start the service. in the same way. why doesn't it do this automatically.

i can see the service is running. it has to check date every 24 hours i dont know why it doesn't do that.

i doubt if my timer control works.

please help me if anybody has any idea.

Ayush
Jul 28 '08 #1
2 717
DrBunchman
979 Expert 512MB
Hi Ayush,

If you are certain that your service is running then the timer must be disabled in your code. When your Tick event is fired do you stop the timer at all?

Dr B
Jul 29 '08 #2
this is my code may be it will answer your question


Expand|Select|Wrap|Line Numbers
  1. ExportService1 : ServiceBase
  2.     {
  3.  
  4.         Timer _timer = new Timer();
  5.         ServiceController controller = new ServiceController();
  6.  
  7.         public ExportService1()
  8.         {
  9.             _timer = new Timer(89000000);
  10.             InitializeComponent();
  11.         }
  12.  
  13.         protected override void OnStart(string[] args)
  14.         {
  15.  
  16.             _timer.Start();
  17.             newfunction(null);
  18.         }
  19.         protected override void OnContinue()
  20.         {
  21.             _timer.Start();
  22.         }
  23.         protected override void OnStop()
  24.         {
  25.             _timer.Stop();
  26.  
  27.         }
  28.         protected override void OnShutdown()
  29.         {
  30.  
  31.             base.OnShutdown();
  32.             _timer.Stop();
  33.  
  34.         }
  35.         public void newfunction(object obj)
  36.         {
  37.  
  38.             Form fr = new Form();
  39.             fr.Export();
  40.  
  41.  
  42.         }
  43.  
Jul 29 '08 #3

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

Similar topics

11
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
1
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
3
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with...
2
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
5
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?...
1
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.