473,516 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Service question in c# .Net 2.0 framework

I am looking for a way to cleanly stop my service in the event of an error.
Within the worker thread, if an unrecoverable error is caught, I would like
to stop my service. Exiting the worker thread doesn't seem to do it. Using
the SCM to stop the service doesn't feel right. Am I missing something? My
service looks like (unrunnable example code below):

public partial class MyService : ServiceBase
{
protected override void OnStart(string[] args)
{
ListenerWorkerThread = new Thread(new ThreadStart(PortListener));
ListenerWorkerThread.Start();
}
protected void PortListener()
{
try
{
//do some work
}
catch (Exception ex) //some really bad error
{
//Write it to the log and stop the service cleanly
}
}
}
Dec 12 '05 #1
3 1174
Hi Ben,

In .NET you can use ServiceController class to start or stop a service.
ServiceController.Stop will stop this service and any services that are
dependent on this service. Please check the following link for more
information.

http://msdn2.microsoft.com/en-us/lib....servicecontro
ller.stop.aspx

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 13 '05 #2
Figured this out. Just needed:

this.stop();
Dec 13 '05 #3
Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 14 '05 #4

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

Similar topics

5
2919
by: Stu Carter | last post by:
Hi, ENV: Windows 2003 Server SP1 (+all updates), VS 2003, .Net 1.1 SP1 We've got an ASP.Net web application using State Service. All is fine until we tried to use the app through a virtual directory with a space in it. e.g. 'http://localhost/My%20App'. The following exception is thrown: ----------
4
2917
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading 'http://mydomain.com:port/webservice.asmx' The operation has timed-out (I've tried with and without using a separate port for the service) The weird thing is...
3
1717
by: Hans Merkl | last post by:
Hi, I am helping to build a web app that's pretty much a wrapper around a web service. The question now is how to store the handle of the web service object between requests. My client is using SQL server for session state so I don't think I can store the web service handle there since it's not serializable. Opening up a connection to...
5
2002
by: Gardar | last post by:
I have a .net webservice, developed with c++ managed extensions. The websrvice returns an xml-document with a reference to a server side xml-stylesheet in the format <?xml-stylesheet href = 'StyleSheet.xsl' type = 'text/xsl'?> This allows the client to retrieve the stylesheet for rendering the xml, if needed. When I test this with IE it...
4
6182
by: jf li | last post by:
I have a Asp.net web application and a Asp.net Web service application. The Web application is using HtmlInputFile to get a 50M size of file selected by end user, read the data of this file and pass the data to the web service. I already modified both web.config files and changed maxRequestLength to 60000(kb). When I debug the upload process,...
2
1756
by: John A | last post by:
I have a Web Service that I am reponsible for that we use for data integration purposes. Recently I have been tasked with sending some of this data to a third party. Because they need to receive the data in real time. They have requested that I subscribe to a Web Service that they have published. The only problem is that they often take...
5
5016
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page that calls the web service to render a vertical strip of images. After doing some research I am unable to find some vb.net code that can assist...
3
6600
dmjpro
by: dmjpro | last post by:
plz send me a good link which can clearify me how the J2EE framework works i want the details information .... plz help thanx
13
6614
by: dancer | last post by:
I have made a new post because when I try to respond to another, I get the error, "Article Rejected -- Ill-formed message id" This is in response to the advice of Juan Libre to install Net Framework Service Pack 1 in order to use ASP.net 1.1 and the net Framework 1.1...
7
3801
by: Rick | last post by:
I have a web service that I converted from VS 2003 Framework 1.1. to VS 2005 Framework 2.0. I tried to use the same IIS web site to run the web service. I deleted the Framework 1.1 files published the 2.0 files changed IIS to use Framework 2.0 and changed the application pool, also restarted IIS. When I try to get to the web service it tells...
0
7276
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...
0
7581
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...
0
7548
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...
0
5714
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...
1
5110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
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...
0
3267
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...
0
1624
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
0
488
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...

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.