473,245 Members | 1,583 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,245 software developers and data experts.

Windows Service (Stopping and Starting)

CG
Hi

I have developed a Windows Service

When I try to start the Service it tells me that it cannot start as there may not be any work to do
When I comment out below line of code in my OnStart event....
objEventLog.EnableRaisingEvents = Tru
....It starts fin

I have the same issue when stopping the service because of below line of code in my OnStop even
objEventLog.EnableRaisingEvents = Fals

I am using .NET 2003 and I have declared objEventLog as..
Friend WithEvents objEventLog As System.Diagnostics.EventLo

Does anyone have any idea as to why this is causing an issue when starting and stopping the service

Thanks
C

Jul 21 '05 #1
5 2566
I may be out of topic. However, do you start a treat in your OnStart()
method so as to perform your real work?

By the way there is a nice article about Windows Service at:

http://www.dotnetcoders.com/web/lear...sservices.aspx

José
"CG" <an*******@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
Hi,

I have developed a Windows Service.

When I try to start the Service it tells me that it cannot start as there may not be any work to do. When I comment out below line of code in my OnStart event....
objEventLog.EnableRaisingEvents = True
...It starts fine

I have the same issue when stopping the service because of below line of code in my OnStop event objEventLog.EnableRaisingEvents = False

I am using .NET 2003 and I have declared objEventLog as...
Friend WithEvents objEventLog As System.Diagnostics.EventLog

Does anyone have any idea as to why this is causing an issue when starting and stopping the service?
Thanks,
CG

Jul 21 '05 #2
CG
No

I start a thread in the elapsed event for my timer.
Jul 21 '05 #3
Personnaly, I would go this way:

**In your Service Class:

protected override void OnStart(string[] args)
{
// Define working directory (For a service, this is set to System)
Process pc = Process.GetCurrentProcess();
Directory.SetCurrentDirectory (pc.MainModule.FileName.Substring
(0,pc.MainModule.FileName.LastIndexOf(@"\")));
// Start the Worker thread
Thread WorkerThread = new Thread(new ThreadStart(m_Worker.DoWork));
WorkerThread.Start();
}
protected override void OnStop()
{
// Ask the Reception thread to stop receiving
m_Worker.Stop();
}

....
private Worker m_Worker;

*****
And then have a Worker class where you do your stuff.
The DoWork() will be the code to execute in your service. It will wait for
a termination request provided by the Service itself through Worker.Stop()
which can
either set an event flag or a local flag to true.
eg:
public void Stop()
{
// In case the thread is running, ask to stop and wait for cleanup
m_bMustStop = true;

if (m_Thread != null)
{
// Wait up to 25 s for the communication to terminate
if (!m_Thread.Join(25000))
{
// Thread was not able to terminate within given time
}
}
}

public void DoWork()
{
// Initialize some thread parameters
m_Thread = Thread.CurrentThread;
m_Thread.Name = "Whatever you want;
...
while (!m_bMustStop)
{

// do your stuff

// Sleep a while (eg. 10s)
Thread.Sleep(10000);
}
}

private Thread m_Thread = null;
"CG" <an*******@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...
No.

I start a thread in the elapsed event for my timer.

Jul 21 '05 #4
On Thu, 26 Feb 2004 13:26:50 +0100, José Joye wrote:
Personnaly, I would go this way: ... excelent demo ...


i just have to say that this excelent post has made it to my code archive -
thanks heaps
--
---------------------------------------------------------
Steven H - B.I.T. Otago Polytechnic, Dunedin, New Zealand
..net Geek
Jul 21 '05 #5
Thanks :-))

José
"Steven H" <sm***********@bigfoot.com - wont work anyway ;)> wrote in
message news:iq******************************@40tude.net.. .
On Thu, 26 Feb 2004 13:26:50 +0100, José Joye wrote:
Personnaly, I would go this way:
... excelent demo ...


i just have to say that this excelent post has made it to my code

archive - thanks heaps
--
---------------------------------------------------------
Steven H - B.I.T. Otago Polytechnic, Dunedin, New Zealand
.net Geek

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
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: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am...
0
by: tshad | last post by:
I have a Windows Service I created that just sets a timer and writes to EventLog every 10 seconds. It installed fine and it actually starts. But it says it doesn't. The progress bar shows the...
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...
5
by: CG | last post by:
Hi I have developed a Windows Service When I try to start the Service it tells me that it cannot start as there may not be any work to do When I comment out below line of code in my OnStart...
4
by: ZQ | last post by:
Hi all! I have few questions regarding .net windows services 1. are onStart, onStop and other "system" events invoked in separate threads than msmq events? 2. if so, is there a way for the...
6
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
7
by: Giulio Petrucci | last post by:
Hi everybody, I've a big problem with a Windows Service I've created using C#. It's a very simple service: it just starts a TcpListener listening for incoming connections on a certain ports....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.