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

  • Home
  • SEARCH
  • 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 507007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:45:36+00:00 2026-05-13T06:45:36+00:00

I have a feature whereby a class in a dll displays a form asking

  • 0

I have a feature whereby a class in a dll displays a form asking a user to clear a fault on a printer before clicking a button to say “Retry”. The users have been just hitting retry without bothering to clear the fault so I am now coding an interlock:
The button on the invoked form is disabled until a call is made to an ‘enable’ method on the form.

This is done with delegate invocation as the events triggering these changes come from other dlls running on different threads.

The form’s ‘enable’ method is wired into an EVENT HANDLER handling an event coming in from a different thread (one that monitors an ethernet IO Server).

The problem I have is that THE “_Fault_StateChanged” EVENT NEVER FIRES. I suspected the cause was the “ShowDialog” and “DialogResult” technique I have used here, but I have used this exact same technique elsewhere in this application.

Any suggestions would be great

See code extract below:

MAIN CLASS excerpt

Public Class StatePrintHandler

    Private WithEvents _RetryForm As frmRetryReject

    Private Delegate Sub delShowRetryDialog()
    Private Delegate Sub delResetEnable()

    Private Sub InvokeResetEnable()
        Dim del As delResetEnable
        del = New delResetEnable(AddressOf ResetEnable)
        del.Invoke()
    End Sub

    Private Sub InvokeRetryDialogue()
        Dim del As delShowRetryDialog
        del = New delShowRetryDialog(AddressOf ShowRetryDialog)
        del.Invoke()
    End Sub

    Private Sub ShowRetryDialog()
        _RetryForm = New frmRetryReject
        _RetryForm.Prep()
        _RetryForm.ShowDialog()
        If (_RetryForm.DialogResult = Windows.Forms.DialogResult.OK) Then
            Me._RetryForm.Visible = False
        End If
    End Sub


Private Sub ResetEnable()
    If (Not IsNothing(_RetryForm)) Then
        _RetryForm.ResetEnable()
    Else
        AuditTrail("Retry form not active, no action", True)
    End If
End Sub


'Event handler for status change coming in on a different thread
    Private Sub _Fault_StateChanged(ByVal sender As Object, ByVal e As Drivers.Common.DigitalSignalChangedEventArgs) Handles _fault.StateChanged
        If (e.NewState) Then
                AuditTrail("Labeller has faulted out during cycling", True)
        Else
                InvokeResetEnable()
        End If
    End Sub
End Class

RETRY FORM CLASS excerpt

Public Class frmRetryReject
    Private Delegate Sub delEnable()
    Public Event Complete()
    Public Sub Prep()
        Me.OK_Button.Enabled = False
    End Sub
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
    Public Sub ResetEnable()
        If (IsHandleCreated) Then
            Dim params() As Object = {}
            Me.Invoke(New delEnable(AddressOf InvokeEnable), params)
        End If
    End Sub
    Private Sub InvokeEnable()
        Me.OK_Button.Enabled = True
    End Sub
End Class

Additional detail in response to Daniel’s comments

The code is incomplete here, it’s an excerpt. The fault object is a subscription to an external library and is a handler for an ethernet IO server.
The _fault StateChanged event fires when a digital input on an IOServer changes. I know the following:
My trace files show the signal change high, this invokes the retry form.
The signal physically changes low again when the retry screen is still showing.
…but the event does not fire

It’s as if the application cannot service the event coming in until the ShowDialog/DialogResult completes – but I am confused about this because I understood that the ShowDialog in .NET 2.0 did not block, I should still be able to service events, and have used this same pattern elsewhere in the app.

A couple of things to note:
The MAIN CLASS is instantiated dynamically at runtime via reflection based on configuration.
This is VS2005 SP2

I will post the entire class in another code box if this helps, but it may crowd the scene…

Thanks
Andy

Imports System.IO
Imports ACS.Interfaces
Imports ACS.Pallet

Public Class StateCimPAKPrintHandler
    Inherits StateBase
    Private WithEvents _ioManager As ACS.Components.DigitalIOManager
    Private _config As StateCimPAKPrintHandlerBootstrap
    Private CONST_OutcomeOK As String = "OK"
    Private CONST_OutcomeRetry As String = "Retry"
    Private CONST_OutcomeException As String = "Exception"

    Private WithEvents _busy As ACS.Drivers.Common.InputSignal
    Private WithEvents _fault As ACS.Drivers.Common.InputSignal
    Private WithEvents _print As ACS.Drivers.Common.OutputSignal
    Private WithEvents _palletRelease As ACS.Drivers.Common.OutputSignal

    Private _labellingInProgress As Boolean
    Private _faulted As Boolean
    Private _retryScreenInvoked As Boolean
    Private WithEvents _timeout As System.Timers.Timer
    Private WithEvents _faultTimer As System.Timers.Timer

    Private WithEvents _RetryForm As frmRetryReject

    Private Delegate Sub delShowRetryDialog()
    Private Delegate Sub delResetEnable()

    Private Sub InvokeResetEnable()
        Dim del As delResetEnable
        del = New delResetEnable(AddressOf ResetEnable)
        del.Invoke()
    End Sub

    Private Sub InvokeRetryDialogue()
        Dim del As delShowRetryDialog
        del = New delShowRetryDialog(AddressOf ShowRetryDialog)
        del.Invoke()
    End Sub

    Private Sub ShowRetryDialog()
        _timeout.Stop()
        _retryScreenInvoked = True
        _RetryForm = New frmRetryReject
        _RetryForm.Prep()
        AuditTrail("Displaying Retry screen", True)
        _RetryForm.ShowDialog()
        If (_RetryForm.DialogResult = Windows.Forms.DialogResult.OK) Then
            AuditTrail("User clicked RETRY LINE on the RETRY dialogue", True)
            _retryScreenInvoked = False
            Me._RetryForm.Visible = False
            Me.SetOutcome(CONST_OutcomeRetry)
        End If
    End Sub

    Private Sub ResetEnable()
        If (Not IsNothing(_RetryForm)) Then
            _RetryForm.ResetEnable()
        Else
            AuditTrail("Retry form not active, no action", True)
        End If
    End Sub

    Public Sub New(ByVal Sequencer As ISequencer, ByVal ParentPlt As ACS.Interfaces.IPallet, ByVal Name As String)
        MyBase.New(Sequencer, ParentPlt, Name)
        _timeout = New System.Timers.Timer
        _faultTimer = New System.Timers.Timer
        _config = New StateCimPAKPrintHandlerBootstrap(Me._myIniFileName, Name)
        _timeout.Interval = _config.CycleTimeoutMS
        _faultTimer.Interval = 750
        _retryScreenInvoked = False
        _RetryForm = New frmRetryReject
        Me._RetryForm.Visible = False
        _ioManager = ACS.Components.DigitalIOManager.GetInstance
        _busy = _ioManager.GetInput("Busy")
        _fault = _ioManager.GetInput("CimPAKFault")
        _print = _ioManager.GetOutput("Print")
        _palletRelease = _ioManager.GetOutput("PalletRelease")
    End Sub
    Public Overrides Sub Kill()
        _ioManager = Nothing
        _RetryForm = Nothing
        _busy = Nothing
        _fault = Nothing
        _print = Nothing
        _timeout = Nothing
        _faultTimer = Nothing
        _pallet = Nothing
    End Sub
    Public Overrides Sub Execute()
        AuditTrail("Pulsing Print Signal", True)
        _print.PulseOutput(3000)
        _labellingInProgress = True
        _timeout.Start()
    End Sub
    Private Sub _busy_StateChanged(ByVal sender As Object, ByVal e As Drivers.Common.DigitalSignalChangedEventArgs) Handles _busy.StateChanged
        _timeout.Stop()
        AuditTrail("Busy signal changed to : " & e.NewState, True)
        If (e.NewState) Then
            _faulted = False
            AuditTrail("CimPAK = Busy High", True)
            _labellingInProgress = True
        Else
            AuditTrail("CimPAK = Busy Low", True)
            AuditTrail("Wait 750 milliseconds for any faults", True)
            _faultTimer.Start()
        End If
    End Sub
    Private Sub _Fault_StateChanged(ByVal sender As Object, ByVal e As Drivers.Common.DigitalSignalChangedEventArgs) Handles _fault.StateChanged
        AuditTrail("Fault signal changed to : " & e.NewState, True)
        If (e.NewState) Then
            If (_labellingInProgress = True) Then
                AuditTrail("Labeller has faulted out during cycling", True)
                _faulted = True
                If (Not _retryScreenInvoked) Then
                    InvokeRetryDialogue()
                End If
            Else
                AuditTrail("Labeller has faulted out between cycles, no action can be taken", True)
            End If
        Else
            If (_retryScreenInvoked) Then
                AuditTrail("Enable button on Retry screen", True)
                InvokeResetEnable()
            End If
            _faulted = False
        End If
    End Sub
    Private Sub _faultTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles _faultTimer.Elapsed
        _faultTimer.Stop()
        If (_faulted) Then
            AuditTrail("System has faulted", True)
        Else
            AuditTrail("No fault occured, assume pallet is OK to release", True)
            AuditTrail("CimPAK cycle complete", True)
            _labellingInProgress = False
            _palletRelease.PulseOutput(3000)
            Me.SetOutcome(CONST_OutcomeOK)
        End If
    End Sub
    Private Sub _timeout_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles _timeout.Elapsed
        _timeout.Stop()
        AuditTrail("Labeller print cycle timed out", True)
        If (Not _retryScreenInvoked) Then
            _retryScreenInvoked = True
            InvokeRetryDialogue()
            InvokeResetEnable()
        End If
    End Sub



End Class

#Region "Bootstrap"
Public Class StateCimPAKPrintHandlerBootstrap
    Private Const CONST_CycleTimeoutMS As String = "CycleTimeoutMS"
    Private _CycleTimeoutMS As Long
#Region "Properties"
    Public ReadOnly Property CycleTimeoutMS() As Long
        Get
            Return _CycleTimeoutMS
        End Get
    End Property
#End Region
    Public Sub New(ByVal IniFile As String, ByVal Name As String)
        Try
            Dim _cfgFile As String = Environ("ACSVAR") & "\" & IniFile
            ' Check to see if the CFG file exits
            If File.Exists(_cfgFile) = False Then
                Throw New Exception("Configuration file does not exist: " & _cfgFile)
            Else
                'Get values
                _CycleTimeoutMS = ACS.Utility.Configuration.GetLong(_cfgFile, Name, CONST_CycleTimeoutMS)
            End If
        Catch ex As Exception
            Throw
        End Try
    End Sub
End Class
#End Region
  • 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-13T06:45:36+00:00Added an answer on May 13, 2026 at 6:45 am

    It’s been a long time since I did any Winforms work, but are you showing the dialog modally? Because that could be the cause of the delegate invokation not arriving.

    Asynchronous delegates work by serializing the invokation details into a memory location internal to the framework and then posting a window message to the top-level window for the relevant thread. Modal dialogs work by going into a message processing loop that steals all the messages for the thread so that only that one dialog can respond. You can see how this might conflict.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feature which allows the user to create projects and view it
I have a clock feature in a VB.NET program that displays the time including
Does Eclipse have a feature that lets you search a project to find all
i have a Sharepoint feature that essentially extends Lists with a new feature, using
I have a custom feature, and I'd like to link to that functionality from
A prospective client wants to have a calendar feature on their website. They want
It seems to be a common requirement nowadays to have a search feature that
I have a need to implement a rating feature and would like to do
I have looked at the SQL Server 2008 feature comparison matrix and it lists
I have come across a quirky feature in Visual Studio and I was interested

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.