473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with ServiceController

I'm using a ServiceController to try to stop and start a service. For development, I've been using the Apache service to experiment with.

I have a simple windows form in vb.net with a start and a stop button, along with a servicecontroller added to the form.

The start button calls ServiceController1.Start and the stop button ServiceController1.Stop. Each works individually.

However, if I start the service with one button and then wait and try to stop it, it doesn't do anything. Or, if I stop the service with the stop button and then try to start, again nothing happens.

If I close the application and then reopen it, it will either stop or start the service. But not stop AND start.

Do you have any idea why this would be?


Here's the code:

Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnStartService_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartService.Click
  2.         If (ServiceController1.Status.ToString <> "Running") Then
  3.             ServiceController1.Start()
  4.         End If
  5.     End Sub
  6.  
  7.     Private Sub btnStopService_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopService.Click
  8.         If ServiceController1.Status.ToString <> "Stopped" Then
  9.             ServiceController1.Stop()
  10.         End If
  11.     End Sub
May 30 '09 #1
2 3461
tlhintoq
3,525 Expert 2GB
Maybe the .Status property is not reporting correctly??

Try commenting the "if" conditions just for testing. That way if you hit 'Stop' it tries to stop no matter the Status. If that works, you know the problem is related to the Status condition or the way you are testing it.
May 30 '09 #2
Hi, thanks for the reply. You're right. It needed a ServiceController.refresh.

That fixed it.
May 30 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David | last post by:
I've written a small windows service, and I'm having a problem that I'm spending a lot more time on than I'd like. If anyone has experienced this problem and has any hints or solutions; they would...
4
by: Prasad | last post by:
Hi, Is it generally acceptable that the SCM says that the service has stopped but the service has spawn a thread which is still doing the cleanup thing which keeps the process running.
1
by: ucasesoftware | last post by:
Dim myController As ServiceController myController = New ServiceController("myWrondName") i try : if myController is nothing then messagebox.show("This service doesn't exist" end if but...
1
by: Tom J | last post by:
What do I have to do to get System.ServiceProcess.ServiceController.ExecuteCommand(int) to work? I have written a service that overrides OnCustomCommand to handle commands sent to it. If I...
2
by: Jonathan Leonard | last post by:
Hello, I'm using the .NET class ServiceController to start my service. After calling start, a subsequent call to ServiceController.Status is returning 'stopped.' I know the service is running...
1
by: Michael Groeger | last post by:
Hi NG, I have written a service which should start at certain time in the morning and stop at a certain time in the evening. For this, I added the following to the Main() method of the service:...
5
by: Primera | last post by:
I use the following method to stop the WMI service: string serviceName = "Windows Management Instrumentation" public static void stopService(string serviceName) { ServiceController services =...
3
by: Bram Hoefnagel | last post by:
Hi, On the 1.1 framework I couldn't find a solution to get a list of services from an other PC. Only a list of services on My local PC. (witch is strange i guess, as you look to the MSDN doc.) ...
3
by: Mika M | last post by:
I'm programming quite simple Windows Service using C# 2005. I also made setup for it into same solution. When I run setup to install service, it's going fine into C:\Program Files\MyCompany\My...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.