To pause an Windows service application

Hi!

Here is some text from e-learning about windows services.
"If you want to pause and restart the Windows service application, you must 
set the CanPauseAndContinue property to True. If this property is set to 
True, you should override the OnPause and OnContinue methods.
However, if the OnPause method releases all the resources in the OnStart 
method, it functions as the OnStop method. You can pause only a portion of 
the work that the service perform while the service perform the remaining 
activities normally."

Now to my question what in meant by the last row when it says
"You can pause only a portion of the work that the service perform while the 
service perform the remaining activities normally."

I mean that if you for example use a timer in the OnStart where you set the 
Enable proprty to true you might set the Enable proprty to false in the 
OnPause and then in the OnContinue set the Enable property to true again.
This is how I understand how OnPause would work.

//Tony


0
Tony
5/4/2010 1:29:00 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

6 Replies
702 Views

Similar Articles

[PageSpeed] 46

"Tony Johansson" <johansson.andersson@telia.com> wrote in message 
news:ODCU7246KHA.4508@TK2MSFTNGP06.phx.gbl...

> Here is some text from e-learning about windows services.
> "If you want to pause and restart the Windows service application, you 
> must set the CanPauseAndContinue property to True. If this property is set 
> to True, you should override the OnPause and OnContinue methods.
> However, if the OnPause method releases all the resources in the OnStart 
> method, it functions as the OnStop method. You can pause only a portion of 
> the work that the service perform while the service perform the remaining 
> activities normally."
>
> Now to my question what in meant by the last row when it says
> "You can pause only a portion of the work that the service perform while 
> the service perform the remaining activities normally."

Wow, yet another piece of bad wording from this book.

What it's saying here is ultimately some ridiculously obvious stuff: you 
can't stop EVERYTHING in your service. Something must continue to execute at 
some level or the service would not be able to come out of its paused state. 
In other words, the Windows message loop is still going to run. Well, duh.

> I mean that if you for example use a timer in the OnStart where you set 
> the Enable proprty to true you might set the Enable proprty to false in 
> the OnPause and then in the OnContinue set the Enable property to true 
> again.
> This is how I understand how OnPause would work.

Yes, you have it right. Another thing you can do is to create a class-level 
(or perhaps global) WaitHandle (like a ManualResetEvent) and sprinkle a 
bunch of WaitOne() calls throughout your code. Then, in the OnPause event 
you could Reset() the object (which will cause any call to WaitOne() to 
block) and in the OnContinue event you can Set() it. 


0
Jeff
5/4/2010 2:01:16 PM
"Jeff Johnson" <i.get@enough.spam> wrote in message 
news:e9szEJ56KHA.5464@TK2MSFTNGP05.phx.gbl...

> In other words, the Windows message loop is still going to run.

I probably should have said "or whatever a service's equivalent is." I'm not 
sure I've ever written a Windows service in C so I don't know if it actually 
has a message pump or not, but you should get the gist of what I was saying 
in my original reply. 


0
Jeff
5/4/2010 4:06:31 PM
> "You can pause only a portion of the work that the service perform while 
> the service perform the remaining activities normally."

As you code what happens in OnPause/OnStart, IMO they just meant that you 
can do pretty much what you want here...

For example, if your service has a request queue, when the service is paused 
you could refuse new requests but keep processing already queued requests 
(that is a "portion of the work" is paused while "remaining activities" 
keeps going on).

--
Patrice 


0
Patrice
5/4/2010 5:50:16 PM
"Patrice" <http://www.chez.com/scribe/> wrote in message 
news:uAptCJ76KHA.356@TK2MSFTNGP05.phx.gbl...

>> "You can pause only a portion of the work that the service perform while 
>> the service perform the remaining activities normally."
>
> As you code what happens in OnPause/OnStart, IMO they just meant that you 
> can do pretty much what you want here...
>
> For example, if your service has a request queue, when the service is 
> paused you could refuse new requests but keep processing already queued 
> requests (that is a "portion of the work" is paused while "remaining 
> activities" keeps going on).

You COULD do that but as a user I would not in any way, shape, or form 
expect that to be what happens when a service is paused. I would expect all 
"normal" work to stop and the only thing to conitnue working in the service 
would be the mechanism to listen for a resume/continue signal.

Decent possible explanation, though.


0
Jeff
5/4/2010 6:25:35 PM
Hi,

> I would expect all "normal" work to stop and the only thing to conitnue 
> working in the service would be the mechanism to listen for a 
> resume/continue signal.

Then  it means the service is stopped as it does nothing else rather than 
waiting to start again. So pausing or stopping the service wouldn't make any 
difference.

Also AFAIK several services such as FTP are done usually this way. It allows 
to stop servicing new requests and at some point later, to ensure that 
nobody uses the service. Still someone that started downloading something 
can download to the end rather than being stuck in the middle (which would 
happen if you just stop the service)...

--
Patrice 


0
Patrice
5/5/2010 12:22:14 PM
"Patrice" <http://www.chez.com/scribe/> wrote in message 
news:%23lJ7Z2E7KHA.3184@TK2MSFTNGP05.phx.gbl...

>> I would expect all "normal" work to stop and the only thing to conitnue 
>> working in the service would be the mechanism to listen for a 
>> resume/continue signal.
>
> Then  it means the service is stopped as it does nothing else rather than 
> waiting to start again. So pausing or stopping the service wouldn't make 
> any difference.

Sure it does! All the service's current state would still be in memory. Do 
you think that using "Sleep" on your computer is the same as "Shut Down"? 


0
Jeff
5/5/2010 5:59:31 PM
Reply:

Similar Artilces:

Web Service Reference not showing XSD
Hi, I just started playing around with web services. When I reference my Web Service in my project, the XSD classes don't get referenced (they don't show). When I switch to class view in my WEb Services rpoject I see them fine. But not when the web service is referenced. What's missing? Pat ...

Replicate Windows Search
Hi When I play my music on the Turntable System I have it creates a copy with the extension OMX which makes my music files messy so I wrote a program to delete these. At the moment I run windows search to find all the ext OMX on all drives I then copy these to a temp folder and run my program to delete from that. This works fine but I wondered if it is possible to replicate the search on all Drives within VB? and store the results direct to the temp folder? I have tried google but so far did not find code to help me. Ron LondonLad wrote: > Hi > When I play my music o...

How to modify WM_CHAR before it is received by the application ?
I cannot modify the following WM_CHAR messages, such as On an application widow, there are "Edit" and "Button". When Button is pressed, the following code will be run HWND hwnd=NULL GetDlgItem(IDC_EDIT1,&hwnd) ::PostMessage(hwnd,WM_CHAR,'a',0) The result should be that write "a" on "Edit" In order to change "a" to "b" be4 "Edit" gets the message, I have writen MsgHook.dll, which has a Hook. As hGetMessageHook=SetWindowsHookEx(WH_GETMESSAGE,MsgProc,GetModuleHandle "MsgHook.DLL" ) ...

Errors in .pst file
I experienced the dreaded blue screen. After the computer re-started I could not open my Outloook, and received the error message, "Errors have been detected the the Outlook.pst file.l It further instructed me to use the Inbox repair tool (Scanpst.exe) to diagnose and repair errors in the file. I ran Scanpst.exe and it detects errors but freezes up when the 'repair' button is clicked. No repairs result. I found the Scanpst.exe in Program Files\Microsoft Office\Office 12. I am running Office 2007 Operating Sytem is XP Service Pack 2 (maybe 3) Is there somewhere I ...

Windows Home Server newsgroup?
SBS friends - I benefit greatly from all of the help provided here on this newsgroup concerning SBS issues. Can you advise if there is a similar group for "Windows Home Server?" Thank you! Mike Windows Home Server http://social.microsoft.com/forums/en-US/category/windowshomeserver/ -- Regards, Dave Patrick ....Please no email replies - reply in newsgroup. Microsoft Certified Professional Microsoft MVP [Windows] http://www.microsoft.com/protect "Mike Stem" wrote: > SBS friends - > > I benefit greatly from all of the help provi...

Windows Mail
I am getting the error messages for the POP3 and SMTP server names can someone tell me the name for these servers in order to get this service up and running elvin Your email account provider(s) has that information. They should have a help page on their website. If you tell us who provides your email account, perhaps someone can assist you. -- Dave N. MS-MVP (Mail) Windows 7 Ultimate 64 http://explore.live.com/windows-live-mail http://download.live.com/wlmail "Elvin Diaz" wrote in message news:#IkoKqFSLHA.4996@TK2MSFTNGP04.phx.gbl... I am getting the er...

Bring window from elevated process to front in Vista
Hi, I'm writing a task switching application and am having difficulty in giving a window belonging to an elevated process the focus. The code I usually use: WINDOWPLACEMENT lpwndpl; lpwndpl.length = sizeof(WINDOWPLACEMENT); ::GetWindowPlacement( hwndAppWindow, &lpwndpl); ::BringWindowToTop (hwndAppWindow); if (lpwndpl.showCmd == SW_SHOWMINIMIZED) { ::ShowWindow (hwndAppWindow, SW_RESTORE); } ::SetFocus (hwndAppWindow); is returning "Access is denied" for BringWindowToTop, ShowWindow and SetFocus. (hwndAppWindow is returned by FindWindow) I've tried calling Allo...

Monitoring Exchange Services
HI All, I'm responsible for Systemmanagement in our company. Since many times we had problems with our exchange Server. Is there a way to monitor this services with snmp ? Generally...I want also monitor any other microsoft services... Thanks Udo ukonstantin@cityweb.de (udo) wrote: >HI All, > >I'm responsible for Systemmanagement in our company. >Since many times we had problems with our exchange Server. >Is there a way to monitor this services with snmp ? > >Generally...I want also monitor any other microsoft services... > > >Thanks > >Udo Y...

GP 7.5 Installtion on Windows 2003 TS Servers
I am trying to install Integration Manager 7.5 on a Windows Server 2003 that already has Great Plains 7.5 installed and running successfully. When I try and install the Integration Manager I get the message 'MDAC 2.7 cannot be installed on this machine. MDAC 2.7 requires any one of the following configurations: Windows 98 Y2K Update 2 w/ IE 4.01 SP2 Windows 98 Second Edition Windows Millenium Windows NT SP5 w/ IE 4.01 SP2 Windows 2000' I believe the fix is related to IM service packs but cannot find the download anywhere. Can anyone help me? Thanx, in advance ...

How to change windows appearance scheme?
Hello, How can I set the windows appearance scheme. Specifically I need to force the appearance scheme to Windows Standard. Also related can the appearance scheme be set to Windows Standard for just the application i.e. without affecting the appearance scheme for other applications and the desktop? Thanks, CarlH. As far as I know, this is not possible. The color scheme is at the discretion of the user. joe On Mon, 31 Jul 2006 12:18:59 -0400, "CharlesC" <Charles@bscinforma.com> wrote: >Hello, > >How can I set the windows appearance scheme. Specifically I ...

Transparent window #2
Hello, How can I create a transparent window with a caption bar and border.And its client is transparent,I can see the picture under the client even if the transparent window is moving. Thanks! You must have made the window transparent my overridding erasebackground and did nothing, Actually that is not transparent its simply you are not erasing the background of ur window and redrawing it that makes see the desktop or what ever is behind the window. If you want a different shaped window, then checkout SetWindowRgn api. "msg_du" <dch1237@msn.com> wrote in message news:uxM...

open a new excel window
hello friends, i am using ms access 2003, i have a form. when i click on a button, i should get the new excel window displaying a particular table values(no need to save the tabel in .xls format, just display is enough) so i followed the code below Dim oExcel As Excel.Application Dim oWB As Excel.Workbook Dim oWs As Excel.Worksheet Set oExcel = New Excel.Application Set oWs = Excel.Worksheets.Application.ActiveSheet oExcel.Visible = True Set oWs = oExcel.ActiveSheet after this, i should insert the values in the new displayed excel window and now i am struck here(even i dont know whether th...

how to upgrade exchange and windows to 2003
Hello I have a single domain model with Windows 2000 domain with 7 domain controllers spread across 2 cities and 7 exchange 2000 servers spread across 2 cities. i want to upgrade to windows 2003 and exchange 2003. Exchange 2000 are currently installed on member servers in the domain. I know that Windows 2003 does not support Exchange 2000, so I will have to upgrade to Exchange 2003 first on member servers and then to Windows 2003 but I would like to know that for domain, is it safe to upgrade first few domain controllers in one city and then roll out exchange 2003 in that city, and th...

Userform as childwindow in statusbar not redrawn when Excel window is resized
I have put a modeless userform without caption as a childwindow into the statusbar window of the main Exel window. So far so good. It moves with the main excel window and stays fully functional inside the statusbar. My problem: When the main excel window is being resized in its width then the statusbar window seems to be redrawn but not the userform childwindow, and therefore the userform isn't visible anymore. I've tried to use the resize event of the userform and as well the resize event of the Excel application to make the userform being redrawn, but both events seem to be ...

IMAP service started but the protocol needs to be started under SysMGR
I have a W2K3 and Exchange 2003 server with no error messages in the event viewer. Even though IMAP is listed as started under Services, I had to go to Exchange System Manager to go to the server, select protocols and then start. There are no error messages in the Event viewer - can anyone tell me how to start this service automatically? It is currently set for automatic in Services but that isn't doing it (even though it says started) If you stop the service with the virtual server online it should be online when the service is again started. You might have to refresh but it shoul...

Problems with Publisher 95 and Windows XP
Hi all- I am having problems getting my copy of Windows Publisher 95 to work with my new computer, which runs on Windows XP. Is this a common problem? Are there any "update" patches that can fix this? I have literally HUNDREDS of files I've made and saved in Publisher 95, and I don't want to give them up. Thanks in advance for any help or ideas. Mike Selvey Nacogdoches, TX Mike Selvey wrote: > Hi all- > > I am having problems getting my copy of Windows Publisher > 95 to work with my new computer, which runs on Windows > XP. Is this a common problem...

Quest: Including CString code to an empty Windows app project...
I have a dll that I am building that should be loadable by many C(N/A for this question just of C++ classes)/C++/VC++/MFC apps and I have kind of a proxy C++ class that packages info into one obj so it can be pass and returned by the functions I export... Going good so far thing are going fine and I want to use CString so I looked up the header I need to include and I find a header(forget the name) go to compile everything and the empty Windows app project show Atl* errors.... So I am wondering what it take to add CString support to header included by the empty Windows app project so the my ...

NNTP service
hi, after googeling, i didn't find a solution.. i want that e2k3 EE rewrites the sender email address to something spam-save in newsgroups [0]. is there a microsoft way to do? regards, wulff [0] either prefix something like spam-(username@domain), add (username@domain.).invalid or some other ways i haven#t thought of.. With event sinks and some programming you can make Exchange do everything. See http://support.microsoft.com/search/default.aspx?spid=1773&query=event+sink&catalog=LCID%3D1033&pwt=false&title=false&kt=PHRASE&mdt=0&comm=1&ast=1&ast=2...

SERVICES or FLAT FEES
What are the differences between "services" and "flat fees" on item type? How we should set up items like: - copy paper; - chemicals used in production line sanitization (are not part of any bill of material); - gloves, goggles... For all these items we don't want to track the balances... Thank you in advance, Radu We have the same issues and have chosen to use Services for all of these items. Don't know if there is any technical difference but we have not seen any practical differences. We've reserved Flat Fee for acutual fees we charge, such as an e...

Question for "application-defined or object-defined error" retrieve outlook contact
Hello, I used the VB to retrieve the outlook XP contact list. When I run the application, it prompt a dialog box. In the following is the dialog box message: A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this? If this is unexpected, it may be a virus and you should choose "No". When I click "Yes", the screen prompt out "Error 287: Application-defined or object-defined error". In normally, if click "Yes", the VB program can retrieve all contact records out, but in my case, it flows this error. Any exp...

Can I use the Windows AD Migration Tool AFTER I've used the AD Connector?
I am migrating from NT/Exchange 5.5 to Windows 2003/Exchange 2003. I have already installed the AD Connector as well as Exchange 2003 into the old Exchange 5.5 domain. All of the NT accounts that were not in the Windows 2003 AD have been replicated into a new container. I am now ready to move the mailboxes over to the new Exchange 2003 server. My question is..Can I use the Windows AD Migration tool to move over the SIDs to the new AD accounts? If I had used the AD migration tool BEFORE I had replicated accounts using the AC connector, it would have replicated the necessary information ...

How can i a resource to an Document/view application?
Hello, i am trying to add an dialog to Document/View application? but i cannt, how can i attach the dialog to the Document? is there a way? thanks cNetWork wrote: > Hello, > i am trying to add an dialog to Document/View application? but i > cannt, > how can i attach the dialog to the Document? is there a way? cNetwork: What does "attach the dialog to the Document" mean? If you have added a dialog template in the resource editor, then you must associate a CDialog-derived class with it. This class can be instanciated and displayed anywhere in your code (provided you...

Pulling up menu in another window
Help! This is a repost with some updated information... I have an application with multiple CFrameWnd derived windows: one for the main window (CMainFrame), another for an editor that can pop up that has its own menu, toolbar, and splitter. Everything works fine (has for years) except that the editor's menu cannot be accessed from the keyboard. Specifically, pressing Alt+F pulls up the menu item from the main CFrameWnd window--even when the editor window has the focus. - I've tried calling BeginModalState() from the editor. This only seems to set the modal state for the main win...

how to let a topmost window follow its parent window?
A dialog-based app, and some controls in it, when right-click on a button, I create a dialog( WS_POPUP, modeless ) topmost, parent window is the button... let it looks a little like a context menu... when my main dialog move, I hope that second dialog move too.. But I can't receive any WM_WINDOWPOSCHANGING WM_MOVING in button's message how to let a topmost window follow its parent window? That's because the button never really moves. The parent window of the button moves, but the button is in the same position releative to the parent window. Anyway the only way I can think of ...

help Cant find Database Properties Window
I've doouble clcked on the entities, ive right clicked too and Ive looked thru every menu item and help but am unable to return to the properties window--ive already used it alot in this document already as i have 15 defined entitiies and about 18 relatonshisps. any ideas...im goin crazy oh yeah, its visio 2003 trial edition -- - ds ...