473,597 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stopping windows service.

Hi all,

I am having one windows service which is updating to database.

On 'Onstop i want to wait till current updation complete. How will i
do this?

Because if i write some lengthy code on onstop it fails to stop and
status remain 'stopping' Later i can't do anything on that service
even i can't uninstall that service.

Please tell me solution for this.

Please help me asap.

thanks in advance.

Jul 30 '07 #1
10 7513
I believe that once you are in OnStop you've invoked the Service Control
Manager and if she can't stop your service in the alloted time, she will blow
up.

You could check if the operation is complete and bail out if it isn't. Other
folks do stuff like this:

private void InvokeOnStop()
{
ServiceControll er sc = new ServiceControll er(this.Service Name);

sc.Stop();
sc.Dispose();
}

-- Although current wisdom indicates that it isn't a good idea.

Peter
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

"archana" wrote:
Hi all,

I am having one windows service which is updating to database.

On 'Onstop i want to wait till current updation complete. How will i
do this?

Because if i write some lengthy code on onstop it fails to stop and
status remain 'stopping' Later i can't do anything on that service
even i can't uninstall that service.

Please tell me solution for this.

Please help me asap.

thanks in advance.

Jul 30 '07 #2
Hi,

thanks for your reply.

But how will i wait for some operation to complete on 'onstop event'.
See like in windows service i can forece user to wait for some
operation to complete by using waitall. That won't cause any
problem. Like that what i need to do in windows service to wait for
current operation to complete.

if u can shed some light on it then it will be really helpful for me,

thanks.

Jul 30 '07 #3
"archana" <tr************ **@yahoo.comwro te in message
news:11******** *************@d 55g2000hsg.goog legroups.com...
But how will i wait for some operation to complete on 'onstop event'.
See like in windows service i can forece user to wait for some
operation to complete by using waitall. That won't cause any
problem. Like that what i need to do in windows service to wait for
current operation to complete.

if u can shed some light on it then it will be really helpful for me,
I usually set a boolean flag true when a process starts and then set it
false when the process ends.

In the OnStop event, I check the value of the flag and wait until it is
false before shutting down the service.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 30 '07 #4

"archana" <tr************ **@yahoo.comwro te in message
news:11******** **************@ d55g2000hsg.goo glegroups.com.. .
Hi all,

I am having one windows service which is updating to database.

On 'Onstop i want to wait till current updation complete. How will i
do this?

Because if i write some lengthy code on onstop it fails to stop and
status remain 'stopping' Later i can't do anything on that service
even i can't uninstall that service.

Please tell me solution for this.

Please help me asap.
When you execute the code each time for the update, you set a global Boolean
flag at the top of the routine to *true* like blnUpdating and set the flag
to false when the routine is exited.

Then in your OnStop you will have code like this.

While blnUpdating
{
make it wait one second by using System.ThreadTi mer.Sleep(wait time)
}

It will stay in the While loop as long as blnUpdating = true.
It will come out of the While loop when blnUpdating is set to false when the
Update routine has exited.

The code in the OnStop will be executed after the loop to stop the service.

The Update routine may need to be running on a child thread while the Onstop
is on the parent thread the thread the service started up on.

You may also want to look at the service's 'CanStop' property by setting it
to true or false as well, but I have never used that property to prevent the
service from stopping.

Jul 30 '07 #5
Hi all,

thanks for replies.

I used same thing. I am getting following error

Could not stop the 'MyTestService' service on Local Computer.

Error 1053: The service did not respond to the start or
control request in a timely fashion.

Can anyone tell what to do to solve this problem. Becase its major
problem and on service i can't restart server everytime if this error
occurs. And i want proper way to stop service.

thanks.

Jul 30 '07 #6
When a service is told to stop, I believe it has 30 seconds before the
Service Control Manager abandons the service.

What you need to do is call the SetServiceStatu s API function through
the P/Invoke layer, using the value returned from the ServiceHandle property
(it is the handle to the service which you can pass to the SetServiceStatu s
function).

In your OnStop method, you would have to wait a little bit, check to see
if the update completed, then call SetServiceStatu s, indicating that you are
waiting (incrementing the dwCheckPoint field of the SERVICE_STATUS
structure, so that your service knows you are doing something).

I can't recall completely, but I think there is an absolute value that
windows will wait for the service to wait, even in light of the calls to
SetServiceStatu s, which if exceeded, will cause the service to be
terminated, so you might want to make sure your update completes in a timely
manner in this case.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"archana" <tr************ **@yahoo.comwro te in message
news:11******** **************@ l70g2000hse.goo glegroups.com.. .
Hi all,

thanks for replies.

I used same thing. I am getting following error

Could not stop the 'MyTestService' service on Local Computer.

Error 1053: The service did not respond to the start or
control request in a timely fashion.

Can anyone tell what to do to solve this problem. Becase its major
problem and on service i can't restart server everytime if this error
occurs. And i want proper way to stop service.

thanks.

Jul 30 '07 #7

"archana" <tr************ **@yahoo.comwro te in message
news:11******** **************@ l70g2000hse.goo glegroups.com.. .
Hi all,

thanks for replies.

I used same thing. I am getting following error

Could not stop the 'MyTestService' service on Local Computer.

Error 1053: The service did not respond to the start or
control request in a timely fashion.

Can anyone tell what to do to solve this problem. Becase its major
problem and on service i can't restart server everytime if this error
occurs. And i want proper way to stop service.
I think the service has blown up somewhere or at some point it went into a
loop somewhere and didn't come out, which in either case it's causing the
Onstop to timeout. You need to debug your service.

Jul 30 '07 #8
Hi,

thanks for your reply.

can u tell me how to do this. Because i searched on net to get
information about it to implement in framework 1.1. But of no luck.

please help me.

thanks

Jul 31 '07 #9
I kind of did already in my previous post? The SetServiceStatu s API is
a windows API function, and you have to call it through the P/Invoke layer.
You can get the definition from http://www.pinvoke.net most likely. You can
also most likely get the definition of the SERVICE_STATUS structure from
there as well.

The ServiceHandle property is not available in .NET 1.1, so you will
have to resort to reflection on the ServiceBase instance (the class you
derive from) to get the value. It would be an implementation detail, but
when you migrate beyond 1.1, you know it will be supported (it's a bit of a
hack, at the least in 1.1, but from what I can tell, the only way to get
what you want).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"archana" <tr************ **@yahoo.comwro te in message
news:11******** **************@ w3g2000hsg.goog legroups.com...
Hi,

thanks for your reply.

can u tell me how to do this. Because i searched on net to get
information about it to implement in framework 1.1. But of no luck.

please help me.

thanks

Jul 31 '07 #10

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

Similar topics

5
2595
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 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
0
1535
by: Daniel O'Brien | last post by:
Hi - any help with this would be greatly appreicated - it has already had me confused for a good few hours! I am using Visual Studio 2003 and the .NET framework 1.1. I have a C# Windows Service, with my own class extending from ServiceBase in the normal fashion. The service starts a remoting object (WKO and singleton) which many clients can then make calls on. Clients may also register with events on the server such that the server...
4
15876
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 : microsoft.public.dotnet.languages.csharp URL :...
0
1048
by: GTS | last post by:
Hi, I have created my application to run as windows service. It is developed using VC++ on Windows 2000 platform. It is working fine with Windows 2000. But I am seeing problems in Windows 2003 while stopping the service. Is there any specific change needed to run it on Windows 2003. Thanks
7
10047
by: Gene | last post by:
I have a Windows Service (VB.NET) that runs 24/7. It queries a Web service 5 to 10 times per hour. About 2 or 3 times a month, it fails. The log indicates that it sends the request to the Web service but there is no return from the service. Stopping and restarting the Windows service cures the problem. Our desire is to cure the problem with appropriate error handling but failing that, is there an easy way to automatically stop and...
0
1001
by: news.microsoft.com | last post by:
Hi, I have a windows service that stops, but in the control panel/services it says that it is running. When I try to stop it, it times out, and just says 'stopping' as its state. I have to kill it by killing the process of via task manager. The windows service logs heaps of events to the event log, and I am wondering if this could be the problem.
0
1420
by: Glen Wolinsky | last post by:
I am creating a Windows service that will check a request queue (database) for pending requests. It will then process each individual request until completed, wait a set time interval and then move on to the next one in the list. The processing routine could take 1-2 minutes to finish processing one request. My question is this: If the service is stopped while the process routine is running, how can I make sure the processing of that...
5
17414
by: chris.hearson | last post by:
How do I programmatically prevent a service from stopping? I want to be able to keep my service running (started), under certain conditions, when a user tries to stop it. I have tried throwing an exception - from OnStop(): the SCM waits for a long time, reports that the service didn't respond in a timely fashion and then leaves the status as stopping. - from Dispose(): the SCM displays an error dialog with the exception details and...
6
8061
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 functions __init__, SvcStop, and SvcDoRun (which contains my server code). After registering the service, I am able to start it with no problems. However, it never stops correctly (net stop returns "service could not be stopped") and service is left...
0
7979
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
8381
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
8262
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
6706
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...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3893
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
2409
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
1
1497
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.