473,401 Members | 2,139 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,401 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 2573
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.