Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 29th, 2006, 01:47 PM
Registered User
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Controlling a Windows Service

Hi All!

I have a windows service that synchs. local data with that on the server. In the onStart() method I start a separate thread and call the synch. method so that the Service starts running.

On the other hand I've a Synch. controlling program, i.e. a desktop app. having one form and a systray icon, much like the Sql Server agent for controlling its service. The service and this program are separate from each other and in the controlling program I simply get to my service by first getting all the services on that system and then getting my service by its name. I can then stop it, start it etc. No problem.

In my synch. service, during synch. there are certain stable points where I can pause the service without affecting the synch., if the service is at that point, I need to give the user through the control program authority to pause it, the problem is how the controlling program know that service is at a stable point or not. I tried, to do it by setting

this.CanPauseandContinue = true;

at those stable points in the service, and then again setting it to false when service is not stable, but the service gave error that these properties cannot be changed while the service is running.

Is there a way that I can set a variable in the service at stable points to true, and then access it in the outside controlling program to enable the pause option?

Any help would be very appreciated!!

Thanks & Regards,

Old October 30th, 2006, 04:53 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

I had a similar scenario to this recently. What I did was to define a global variable, say canPause, and initially set it to true. When you enter a section where you don't want to pause then set it to false and return it to true when the critical part is finished. In the event handler that pauses you check beforehand the value of canPause before taking action. I had the actually work done by the service on a separate thread so that I could stop and start things separately from the actual service.

The user can still send a pause message but it will have no effect until the thread enters a zone where it is safe to do so.


Joe (Microsoft MVP - XML)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Service monika.vasvani ASP.NET 1.0 and 1.1 Professional 1 January 3rd, 2009 05:39 PM
Impersonate with windows service for Service A/C vinod_yadav1919 C# 0 October 18th, 2008 02:29 PM
windows service MunishBhatia WinForms/Console Application Design 0 September 27th, 2007 10:27 AM
Accessing Windows service from a windows app sajid08 C# 1 October 6th, 2006 10:25 AM
Windows Service hunghung General .NET 3 January 20th, 2005 01:43 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.