Solved

vb.net windows services

Posted on 2011-02-27
2
156 Views
Last Modified: 2012-05-11
Is there anyway to control a service from code? I want to be able to stop a service based on it reading a flag from within a database. It is a multithreaded program. The threads are controlled by a db flag. Is there a way in code to tell the service to stop?
0
Comment
Question by:rutledgj
2 Comments
 
LVL 13

Accepted Solution

by:
agarwalrahul earned 250 total points
ID: 34994132
please try this code:

Private Sub StartStop()
        Dim service As ServiceController = New ServiceController("MyServiceName")
        If ((service.Status.Equals(ServiceControllerStatus.Stopped)) Or
            (service.Status.Equals(ServiceControllerStatus.StopPending))) Then
            service.Start()
        Else
            service.Stop()
        End If
    End Sub
0
 

Author Comment

by:rutledgj
ID: 34996660
Could you explain how this works? How does the service.status flag get set? Also, how does this method get called?
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio .Net 2012 and Crystal Reports 9 67
C# Single Form 8 42
Get the selected ValueMember of Combobox 5 30
VB.Net - KeyPress Event 4 36
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question