473,788 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Terminating a service when a worker thread terminates

Hello:

I created a basic windows service that polls a db and sends emails to
our subscribers. In the onstart method I create a new thread and send
it on its way to do work. It should never end unless told to do so by
the onexit event I implemented in the worker object. However there
are the rare circumstance that the thread hits a catastrophic error
and exits the main process loop. So basically the service is now
useless. Is there a way that I can periodically check the state of
the thread in the service and take down the service normally in the
service implmentation.

Please let me know what you think,

Tim
Nov 16 '05 #1
2 1793
One common way to do this is to create another thread that acts as a "sentinal"o ver the first. It sole job is to monitor the health of the worker thread and inform the service of a problem

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<5e************ **************@ posting.google. com>

Hello:

I created a basic windows service that polls a db and sends emails to
our subscribers. In the onstart method I create a new thread and send
it on its way to do work. It should never end unless told to do so by
the onexit event I implemented in the worker object. However there
are the rare circumstance that the thread hits a catastrophic error
and exits the main process loop. So basically the service is now
useless. Is there a way that I can periodically check the state of
the thread in the service and take down the service normally in the
service implmentation.

Please let me know what you think,

Tim

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #2
You should be able to handle any error by catching them inside your loop and
ignore/report them, and continue.

--
William Stacey, MVP

"T Conti" <tc****@hotmail .com> wrote in message
news:5e******** *************** ***@posting.goo gle.com...
Hello:

I created a basic windows service that polls a db and sends emails to
our subscribers. In the onstart method I create a new thread and send
it on its way to do work. It should never end unless told to do so by
the onexit event I implemented in the worker object. However there
are the rare circumstance that the thread hits a catastrophic error
and exits the main process loop. So basically the service is now
useless. Is there a way that I can periodically check the state of
the thread in the service and take down the service normally in the
service implmentation.

Please let me know what you think,

Tim


Nov 16 '05 #3

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

Similar topics

3
20131
by: DE | last post by:
Hello, I have an app with embedded Python. Python scripts create their own threads and I need to terminate these threads at the point where the user wants to leave the application. I use threading.Thread as base classes. I have tried to use call the join method of the python thread objects from C++. But although the call succeeds, the threads don't exit.
2
2772
by: Russ McDaniel | last post by:
Originally posted to microsoft.public.dotnet.distributed_apps with no response. Reposted here with additional thoughts. --- Hello, I'm writing a Windows service which performs some potentially long-running, uninterruptable processes. When the service starts, I create a separate worker thread to perform the work so as to not block the service control manager upon startup. The design quandry I'm running into though is how best
2
5560
by: Drew Stoddard | last post by:
We are working in C#/Winforms and are using asynchronous client-side web service calls (the Begin... and End... methods supplied by the web reference creation). Many of these calls are contained in Windows forms that the user can close before the web service call has completed. This seems to be working fine, but I wanted to check to see if anyone has experienced any problem with this. Specifically this is what I need to know: Is it...
6
25202
by: Dmitri Shvetsov | last post by:
Hi All, Did somebody see the situation when the VS refuses to debug the Web Service at all? I can't catch why, the initially created Web Service can be debugged very easy but after some changes in a source code, maybe the source code becomes bigger that some hidden threshold, the debugger can't enter into this code anymore. I can use this web service, all methods but can't see in debugger what's going on. I have already catched this...
4
15896
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 :...
2
1714
by: Dave | last post by:
I have an application that queries SQL Server and Index Server using ADO. I'd like to have a feature where a user can cancel a long-running query. What I plan on doing is to move my query code to a worker thread which will then post a message back to the main thread when it's done. Then, the application can have a button that a user can press to terminate the worker thread. That way, the app stays responsive during a long-running query. ...
1
2809
by: Vikram | last post by:
Thanks Jonathan for the prompt reply. We have developed a program in C#, originally a windows application, that was invoking a worker thread. The threading mechanism works fine in this case. The worker thread gets invoked and an excel file is created. Currrently, we are trying to convert this program into a windows service. We have removed any code that writes any kind of output. The service gets created and we can start it without any...
23
7595
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an unrecoverable error occurs. When that case occurs, I create a ServiceController object and call the Stop() method. However - I get an exception thrown saying access denied. If I switch to using the LocalService account it works fine, but I lose...
6
23745
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100); } The problem is that I don't know how to terminate the thread when my class
0
9656
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
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10172
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...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
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
5398
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...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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
3
2894
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.