Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:03:22+00:00 2026-05-29T08:03:22+00:00

A few weeks ago I wrote a wrapper for the ServiceController control to enhance

  • 0

A few weeks ago I wrote a wrapper for the ServiceController control to enhance and streamline the base ServiceController. One of the changes I made was to add a monitoring component using the System.Threading.Timer object. On any change of status, an event is raised to the parent class. The actual monitoring works fine, but when the event is handled in the main form, my program abruptly ends – no exceptions, no warning, it just quits. Here’s a skeleton version of the control:

Public Class EnhancedServiceController
    Inherits ServiceController

    Public Event Stopped(ByVal sender As Object, ByVal e As System.EventArgs)
    Public Event Started(ByVal sender As Object, ByVal e As System.EventArgs)

    Private _LastStatus As System.ServiceProcess.ServiceControllerStatus

    Private serviceCheckTimer as System.Threading.Timer
    Private serviceCheckTimerDelegate as System.Threading.TimerCallback

    ...

    Private Sub StartMonitor()
        MyBase.Refresh()
        _LastStatus = MyBase.Status
        serviceCheckTimerDelegate = New System.Threading.TimerCallback(AddressOf CheckStatus)
        serviceCheckTimer = New System.Threading.Timer(serviceCheckTimerDelegate, Nothing, 0, 60*1000)
    End Sub

    Private Sub CheckStatus()
        MyBase.Refresh()
        Dim s As Integer = MyBase.Status
        Select Case s
            Case ServiceControllerStatus.Stopped
                If Not s = _LastStatus Then
                    RaiseEvent Stopped(Me, New System.EventArgs)
                End If
            Case ServiceControllerStatus.Running
                If Not s = _LastStatus Then
                    RaiseEvent Started(Me, New System.EventArgs)
                End If
        End Select
        _LastStatus = s
    End Sub

End Class

And the form:

Public Class Form1
    Private Sub ServiceStarted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Started
        Me.TextBox1.Text = "STARTED"
    End Sub

    Private Sub ServiceStopped(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Stopped
        Me.TextBox1.Text = "STOPPED"
    End Sub
End Class

If I had to guess, I’d say that there’s some sort of thread problem, but I’m not sure how to handle that in the form. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:03:23+00:00Added an answer on May 29, 2026 at 8:03 am

    IF it is a threading issue then you are probably trying to update the UI from a non-UI thread.

    So something like this should solve that…

    Private Delegate Sub UpdateTextBoxDelegate(byval tText as String)
    
    Private Sub UpdateTextBox(byval tText As String)
        If Me.InvokeRequired Then
            Me.Invoke(New UpdateTextBoxDelegate(AddressOf UpdateTextBox), tText)
            Exit Sub
        End If
    
        TextBox1.Text = tText
    End Sub
    
    Private Sub ServiceStarted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Started 
        UpdateTextBox ("STARTED")
    End Sub 
    
    Private Sub ServiceStopped(ByVal sender As Object, ByVal e As System.EventArgs) Handles ESC.Stopped
        UpdateTextBox("STOPPED")
    End Sub   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really frustrated with this one. A few weeks ago I got it working
A few weeks ago I wrote a CSV parser in python and it was
A few weeks ago I wrote an SNMP relayer for our ops group. They
A few weeks ago I found somewhere a code that allows one to dump
I wrote these helper functions a few weeks ago and I feel like I'm
i have a bit of code that i wrote a few weeks ago (the
A few weeks ago, I was assigned to evaluate all our programmers. I'm very
A few weeks ago I opened up a hole on my shared server and
A few weeks ago I asked the question Is a PHP, Python, PostgreSQL design
A few weeks ago, I asked a question about how to generate hierarchical XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.