Stop Windows Service

Hi,

What is the normal way to stop a servie from within the servie itself ??

BR
Peter 


0
Peter
6/17/2010 9:06:33 AM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

5 Replies
717 Views

Similar Articles

[PageSpeed] 9

Peter Larsen [CPH] wrote:
> Hi,
> 
> What is the normal way to stop a servie from within the servie itself ??
> 

<http://www.google.com/#hl=en&source=hp&q=Windows+service+shutdown+programically&btnG=Google+Search&aq=f&aqi=&aql=&oq=Windows+service+shutdown+programically&gs_rfai=C6ZxLawwaTJ2TB5G2zQTCoKWfAwAAAKoEBU_QI6Z8&fp=652ba8543c4f91ab>
0
Mr
6/17/2010 11:52:58 AM
On 17-06-2010 05:06, Peter Larsen [CPH] wrote:
> What is the normal way to stop a servie from within the servie itself ??

The service extends ServiceBase and that has a Stop method.

I have never tried it, but I would expect it to
stop the service.

Arne

0
ISO
6/18/2010 2:11:16 AM
Thanks for your comments.

I know about ServiceBase.Stop(), but what is best practice ?

What is if i want to stop with error (Environment.Exit() or throw an 
exception) ?
Both ways, the service stops immediately without any cleanups (no go i would 
say).

/Peter 


0
Peter
6/18/2010 10:52:38 AM
"Peter Larsen [CPH]" <PeterLarsen@community.nospam> wrote in message 
news:Odw7fRtDLHA.352@TK2MSFTNGP02.phx.gbl...

> Thanks for your comments.
>
> I know about ServiceBase.Stop(), but what is best practice ?
>
> What is if i want to stop with error (Environment.Exit() or throw an 
> exception) ?
> Both ways, the service stops immediately without any cleanups (no go i 
> would say).

So write a cleanup method whose final line calls Stop(). Stopping with an 
error code is a bad idea in my opinion, like some throwback to DOS. I 
recommend writing an error to the event log instead of an returning error 
code. 


0
Jeff
6/18/2010 3:04:26 PM
Hello Peter,

If you want to log the error in service exiting, you can consider calling 
EventLog.WriteEntry to write an event log to the system logs.

Check this KB aritcles, http://support.microsoft.com/kb/307024 and the 
codes are applicable to the Windows Service application.

By the way, the managed priority subscriber support migrates from the C# 
newsgroup to C# forum. So if you have further questions about programming 
via C#, we suggest you raise them in the forum,
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads

And you can get more information about the priority subscriber support 
migration from this page,
http://msdn.microsoft.com/en-us/subscriptions/aa974230.aspx#CSHARP


Best regards,
Ji Zhou - MSFT

0
colbertz
6/22/2010 7:47:33 AM
Reply:

Similar Artilces:

disable snap-to while dragging tab stops?
How do I drag a tab stop to arbitrary position without it snapping to the tick marks on the ruler? I tried holding down shift, ctrl, alt. None of them works. I even turned off everything in the arrange->snap menu. Publisher 2003. Set the tab to about where you want it, zoom to 200%, open the tab dialog and input the number where you want the tab positioned, click set. The tab button can be dragged to your toolbar by customizing. This is the best that Publisher can do... -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "p...

windows search
This was originally posted to windowsxp.general but got no responses so I am going to post here now thinking that I posted to the wrong group. If there is another group I should post to please let me know. WIN XP SP3 When in Windows Explorer and click on a folder Windows Search comes up. What I really want it to do is just open the folder. It used to do that but now I have to right click and then select open. I'm not even sure what changed that caused this "new version" of Search to come up. I looked in Tools|Folder Options|View but don't see anything that l...

stops responding
A few days ago while trying to balance one of my accounts, Money would start hanging and I had to kill the process and created a LRD file. My file is only 12MB and it has been fine until recently. I am using Money 2007. I should have put my system specs. I have a P4 3.8GHZ w/ 2GB RAM running XP Pro. When I have Money open, I typically only have Messenger, a browser, and sometimes Acroabat Reader running also. "Casey" wrote: > A few days ago while trying to balance one of my accounts, Money would start > hanging and I had to kill the process and created a LRD file. ...

blue stop screen 0x0000007E
stop error code after windows installs drivers. this is new hdd and mobo but problem persists.oxoooooo7e (oxf748eobf oxf78da2o8,oxf78d9fo8....was doing it with last mobo and hdd...help please!!! -- thanks one and all for your helping hands xerxies wrote: > stop error code after windows installs drivers. this is new hdd and > mobo but problem persists.oxoooooo7e (oxf748eobf > oxf78da2o8,oxf78d9fo8....was doing it with last mobo and hdd...help > please!!! That *is* a driver issue. You are installing the incorrect drivers or need to contact the manufacturer of said ...

Windows mail cannot be opened...
Ok I too am getting the error of Windows mail cannot be opened, (out of memory/ disk full) click ok and the 2nd popup appears.... "Windows mail couldn't be started because MSOE.DLL could not be initialized..... Ok have read many of the posts, so let me say this before Gary puts in his usual "It's your Antivirus" comment.... I run NIS (Norton internet security) I do manual updates and haven't in the last 2 days/ I have not down loaded and MS updates (I do those manually as well) Nothing has changed on my PC, yet today I started getting the same err...

recipient policy stopped working
Hello All, I'm seeing an issue in my Exchange 2003 environment where an admin will create a new account and the recipient policy does not populate the users email address. This just started happening a few days ago here in the US... It happened in our UK office last week but I thought that might have been user error on the admin. We are in mixed mode with Exchange5.5, which we have been for almost a year. I did how ever remove some old 5.5 servers but the last one I removed was almost a month ago, so i don't think it would be that. I know you need to ask this question so yes th...

Some windows never appear
In Money 2006, some windows never open and the program appears to 'hang'. Examples are the Advanced Search and the Customize... link in reports. In both cases the window never appears and Money program loses focus. The only way to fix is to hit ESC and get control back to Money. But I can never see those windows. I wish we could find an answer. I have the same problem?? Are you using dual monitor setup? I am. "Tyler Robbins" wrote: > In Money 2006, some windows never open and the program appears to 'hang'. > Examples are the Advanced Search and the Cus...

How to turn off Windows explorer?
Hello, I want to build an OS design for a kiosk application, there should only be the application programs user interface, no other possibilities for user operations. I have read that it is possible to keep the Windows explorer from being built into the image but I can't find the catalog item that controls it. Can anybody help me please Thank you very much. Martin Martin wrote... > I want to build an OS design for a kiosk application, there should only > be > the application programs user interface, no other possibilities for user > operations. I have...

Outlook Express problem in Windows XP
Hello, I encountered the following error when I ran Outlook Express in Windows XP. "Outlook Express could not be started. The application was unable to open the Outlook Express message store. Your computer may be out of memory or your disk is full. Contact Microsoft Support for futher assistance. (0x8007007E, 126)" Do you know how to resolve this problem? If you know, please reach me at big_hkkid@yahoo.com Thanks in advance. Lee Post in microsoft.public.windows.inetexplorer.ie6.outlookexpress -- mdh "Lee Chiu" <anonymous@discussions.microsoft.com> wrote ...

How do I stop a cc email to myself from going to deleted folder
Sometimes when I send an email, I want to keep a copy ofr myself. When I enter my email address in the cc part, this always goes straight to the deleted folder, even though I have my email listed as a safe sender. Any suggestions? On 13/03/2010 01:53, technochallenged wrote: > Sometimes when I send an email, I want to keep a copy ofr myself. Outlook automatically keeps a copy of every email you send in the Sent Items folder. There is no need to cc yourself. "technochallenged" <technochallenged@discussions.microsoft.com> wrote in message news:D4...

Changing the Password for the Mail Services Account
Is there an issues with doing this on an exchange 5.5 server. I think not, but figure I would ask first. Thanks, SRG Actually, yes there are issues. In addition to changing the password from within User Manager, you would also need to change the password on all of the Exchange Services in the Services applet (Control Panel, Services) as they run under the context of that user account, and also in Exchange Admin on the properties of the Configuration container, Service Account Password tab. -- Ben Winzenz Exchange MVP "SRG" <mlaufer@srg.com> wrote in message news:ae...

Warning on Windows Mobile on Inaccessible Server?
I need to way to know if my server is up and running at any time even when I’m away from work. I am thinking of using Windows Mobile 5 phone who would always be connect with my Exchange server. In the case that Windows Mobile 5 phone would be unable to connect to my Exchange server; I would get a warning message. Is that possible? If there anyway for a Windows Mobile phone (Or Blackberry phone) to do a ping on my exchange server? Thank you. The whole server working perfectly,. just the Exchange services or what? "Simon Tremblay" <Simon Tremblay@discussions.microsoft.com&...

3197: The microsoft Jet Database Engine stopped the process because you and another user are attempting to change the same data at the same time
Hello, I have a fairly large (For Access - its slated to be transferred to MySQL) backend that allows the user to use the database's front end normally to store and retrieve data. However when I try to open the database I get the Error "The microsoft Jet Database Engine stopped the process because you and another user are attempting to change the same data at the same time". This isn't true because I have it on my local computer. I've tried importing to a new DB file and I get the same error. The original DB will not open to allow import (show table list) and show er...

Complex Time Window / date based calculation
Excel 2002 SP3 Win XP HE *Follow-up to: microsoft.public.excel* Hi, I have the following: Columns A B C D E F G H I J Date Field 1 Field 2 Field 3 Field 4 Field 5 Field 6 Field 7 Field 8 Field 9 12/31/1996 xyz 58979 23539 1880 1937 1837 1930 100 1/30/1997 xyz 58979 23539 1925 1965 1787 1822 -5.60% 94.40 2/28/1997 xyz 58979 23539 1925 1965 1787 1822 -5.60% 94.40 3/31/1997 abc 58979 23539 1925 1965 1787 1822 -5.60% 94.40 etc. I need to be able to modify the last column (column J) so that the number 100 starts at TODAY() - 1 year (the "-" is a minus sign) as we...

Stop all macros
I have a button on a form, which should do different things depending on 1. The data contained within the current record; 2. Whether the current record is a 'new record'; 3. Whether the current record is the first record in the form. On click, an embedded macro is initiated. Each step in the embedded macro has a condition and a corresponding 'RunMacro' action. All the conditions are mutually exclusive, and each sub-macro has a final step of 'StopAllMacros'. So the embedded macro should trigger one, and only one sub-macro. However, it appears that what is act...

Windows 7
Hi guy's - I just built a Windows 7 Media Center and when I log into windows there is a black border all the way around my LCD 32'' screen. NO DVD or any movie is playing yet, just pure Windows. My Screen Resolution is already set to the max of 1920x1080 - lanscape. Obviosly when I play a DVD the DVD also does not show-up in full-wide-screen, etc.. Any ideas? What make/model 32" LCD? If a Samsung make sure you read the PC chapter in the User's manual closely. What interface are you using to the TV? "Gabriel" <Gabriel@discussions.m...

Publisher 2003 Opens Multiple Windows
I work in an engineering firm where we use multiple files in Publisher. Since we upgraded to Office 2003, when we open a file it brings up another publisher window. In Publisher 1998 when you would open a file and was done with it, you could click on another file and would open in the same window and keep your path of picture inserts, hyperlinks, etc. Is there a way to allow Publisher 2003 to do this? It would making working on our sheets easier. Publisher 98 could have one document open at a time unless you opened a completely new session (two instances of Publisher opened). If you sav...

I would Like to Receive the Windows Update Services for my Account
Thanks for your service... I would like to receive the Windows Updates for this acco unt at any time; please, take note about it. Thanks. -- FCAMPBELL01 Signatureship: ix/lc=1030 wcfla/lc=xxx-xx60310. fset/lc=xxx-xx25377. FCAMPBELL01 wrote: > Thanks for your service... I would like to receive the Windows > Updates for this acco > unt at any time; please, take note about it. I have taken note. Many others that are your peers likely will as well. However - I would bet the question would be, "Why should we care?" This is a peer-to-peer newsgroup - a foru...

Stopping the scroll bar
Hi all, this is my first time. I don't know if this is the right place for this problem but here I go. I have created a template of an invoice the size of an A4 and would like to stop the scroll bar moving both horizantally and vertically in normal view just as if it was in print view. Is that possible through VBA and if yes what is the code that I would need to achieve such task. Thanks in advance --- Message posted from http://www.ExcelForum.com/ Not too sure what you are after but you can remove the scrollbars with <Tools - Options> and then in the View tab, at the bottom,...

Try this corrective pack for Windows
--kpzuywjrnabxmxz Content-Type: multipart/related; boundary="miyjilgvr"; type="multipart/alternative" --miyjilgvr Content-Type: multipart/alternative; boundary="mssjcanbw" --mssjcanbw Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Customer this is the latest version of security update, the "September 2003, Cumulative Patch" update which eliminates all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express. Install now to protect your computer from these vulnerabilities, the mo...

Stopping a Campaign Temporarily
Hi, My client has executed the campaign in Jan 1st 2006 and the end date is Dec 31st 2006. But he wants to stop the campaign temporarily from 15th July 2006 and again start it from 1st Aug 2006. So what is that I need to do for this thing, i have never come across this kind of situation before. Thanks in advance. Regards, Shabbir. ...

POP3 access problem in Outlook XP / Windows XP
Using Outlook XP on Windows XP, when we tried to download mails from POP3 server, it is taking atlease 2 minutes to ask password or to start donloading message. Why is there a 2 minute delay? But the same is taking less than 1 minute in Outlook 97 + Windows 98 combination. This is a long shot, but try disabling the integration with Instant Messenger in Tools | Options | Other and see if that speeds things up. -- Jocelyn Fiorello MVP - Outlook *** Replies sent to my e-mail address will probably not be answered -- please reply only to the newsgroup to preserve the message thread. *** ...

Are there and Built-in Application Failover Technologies in .NET and/or Windows Server 2008 (or SQL Server)
Hi all A bit of a general question, hence the cross-posting. I have a .NET application running on a Windows Server 2008 server. For resilience, I want to run it on another server simultaneously, but only one instance of the application can be 'active' at any one time. In the event that the active instance of the application fails for some reason, I want the passive one to take over. What techniques are there available to make this an automatic process? Of course, I can roll my own, as it were, and I would be interested in how other people would implement a bespoke ...

Would you stop for a moment?!
Excuse me!! Would you stop for a moment?! O...man...Haven't you thought-one day- about yourself ? Who has made it? Have you seen a design which hasn't a designer ?! Have you seen a wonderful,delicate work without a worker ?! It's you and the whole universe!.. Who has made them all ?!! You know who ?.. It's "ALLAH",prise be to him. Just think for a moment. How are you going to be after death ?! Can you believe that this exact system of the universe and all of these great creation will end in in nothing...just after death! Have you thought, for a second, How to save you...

Default Window Sizes
Hi, Does anyone know if there is a way of changing the size and location of the default window which opens when you view an object in design view? For some reason, when I design a table, the window takes up my entire application window, and when I open a query, the window is wide (off the edge of the app window) and has very little height. Just annoying as it means I need to resize these windows every time I design a table or a query. Many thanks to anyone who can give me any pointers, Jim P.S. I am using WinXP/Acc2003 Try hitting the save button after you've resized and repos...