Results 1 to 10 of 10

Thread: Program hang when running outside of VS

Threaded View

  1. #1

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Program hang when running outside of VS

    Hi,
    I hope someone can help explain this very weird behavior that I'm running into. I have a small program that communicates with a testing device over the serial port. The program will send some commands to the tester and receive some test data back. That test data is saved to a database and displayed on the UI. During debugging in Visual Studio 2015, everything works correctly as designed. However, when the program is released and tried to run as a standalone app, it will hang when trying to update the UI with the test data (the test data received is all valid and successfully saved to the database, but the program hangs when trying to display that data on the UI when calling "PopulateForm"). I'm stuck and unable to determine the cause of this behavior.
    In summary:
    - Program runs properly during debugging in VS
    - It will hang when running outside of VS
    - Narrow down to this line when it gets stuck: Me.BeginInvoke(New UpdateUI_Delegate(AddressOf PopulateForm))
    - When the execution reaches that code line, the program becomes unresponsive and needs to be killed via task manager.

    What I have tried:
    - Rewrite that code line using different ways, i.e. Me.BeginInvoke(Sub() PopulateForm())... This made no difference
    - Tried using Invoke instead of BeginInvoke: made no difference.
    - Spinning off another thread to perform the PopulateForm task - also made no difference
    - Set Form.CheckForIllegalCrossThreadCalls = False then call PopulateForm() without Invoke or BeginInvoke: this works but I try to avoid it if there is a more proper way to do it.

    Here is the relevant code:
    Code:
    Private Delegate Sub UpdateUI_Delegate()
    
     Private Sub RS232_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles RS232.DataReceived
            If Not (e.EventType = SerialData.Eof) Then
                Dim incomingData = Me.ReadIncomingSerialData()
                If incomingData IsNot Nothing Then
                    ProcessIncomingSerialData(incomingData.ToArray)
                End If
            End If
        End Sub
    
     Private Sub ProcessIncomingSerialData(ByVal rx_buf As Byte())
            Me.StatusUpdate("Process incoming serial data...")
    
            Dim x As Integer = rx_buf.Length
            Dim y As Integer = 0
            Dim crc As Byte = 0
    
            'code removed....
    
                Select Case rx_buf(0)   
                    Case UPLOAD_LOG_DATA_COMMAND 
    
                        Me.StatusUpdate("Received UPLOAD_LOG_DATA_COMMAND")
    
                       'code removed...
    
                        Me.StatusUpdate("Reply_To_ATE(ASCII_ACK)")
           
                    Case REQUEST_EE_STRING_COMMAND
    
                        Me.StatusUpdate("Received REQUEST_EE_STRING_COMMAND")
    
                       ' code removed....
                     
                    Case SAVE_RECORD_COMMAND
    
                        Me.StatusUpdate("Received SAVE_RECORD_COMMAND")
                        ' Save data record to database
                        '         
                        If SaveDataRecords(ErrorMessage) Then
                            Me.StatusUpdate(String.Format("Data records for serial number '{0}' saved to database.", Me.lblSerialNum.Text), Color.Blue)
                            
                            Me.BeginInvoke(New UpdateUI_Delegate(AddressOf PopulateForm))
    
                            Reply_To_ATE(ASCII_ACK)
                            Me.StatusUpdate("Reply_To_ATE(ASCII_ACK)")
    
                        Else
                            Reply_To_ATE(ASCII_NACK)
                            Me.StatusUpdate("Reply_To_ATE(ASCII_NACK)", Color.Red)
                        End If
    
                    Case UPLOAD_EE_STRING_COMMAND
                        Me.StatusUpdate("Received UPLOAD_EE_STRING_COMMAND")
                       
                       'code removed
    
                End Select
            Else
                Reply_To_ATE(ASCII_NACK)
                Me.StatusUpdate("Reply_To_ATE(ASCII_NACK): the value of CRC is incorrect.", Color.Red)
            End If
    
        End Sub
    
     Sub PopulateForm()
    
            Me.StatusUpdate("Populating form...")
            Try
                Me.lblTestDate.Text = ATEData.TestDate.ToString("G")
                Me.lblSerialNum.Text = ATEData.SerialNumber.Substring(0, SN_LENGTH)
                Me.txtVoltageSupply.Text = ATEData.Supply_Voltage.ToString("F3")
                Me.txtVoltageRawMin.Text = ATEData.MinRawTreadleVoltage.ToString("F3")
                Me.txtVoltageRawMax.Text = ATEData.MaxRawTreadleVoltage.ToString("F3")
                Me.txtVoltageRawDelta.Text = (ATEData.MaxRawTreadleVoltage - ATEData.MinRawTreadleVoltage).ToString("F3")
                Me.txtVoltageMVMMax.Text = ATEData.MaxNVMTreadleVoltage.ToString("F3")
                Me.txtVoltageNVMMin.Text = ATEData.MinNVMTreadleVoltage.ToString("F3")
                Me.txtMotorLoadLow.Text = ATEData.Low_Motor_I.ToString("F1")
                Me.txtMotorLoadMed.Text = ATEData.Med_Motor_I.ToString("F1")
                Me.txtMotorLoadHigh.Text = ATEData.High_Motor_I.ToString("F1")
                Me.txtVoltagePBReleased.Text = ATEData.PB_Released_Voltage.ToString("F3")
                Me.txtVoltagePBPressed.Text = ATEData.PB_Pressed_Voltage.ToString("F3")
                Me.txtLEDLoadX.Text = ATEData.LoadCurrentX.ToString("F1")
                Me.txtLEDLoadY.Text = ATEData.LoadCurrentY.ToString("F1")
                Me.txtLEDLoadZ.Text = ATEData.LoadCurrentZ.ToString("F1")
                Me.rtbNVMData.Text = Module1.ConvertToHexString(ATEData.NVMData)
                Me.txtCRCHeaderNVM.Text = Conversion.Hex(CRC_Data.NVM_Header)
                Me.txtCRCModuleNVM.Text = Conversion.Hex(CRC_Data.NVM_Module)
                Me.txtCRCHeaderCalculated.Text = Conversion.Hex(CRC_Data.Calculated_Header)
                Me.txtCRCModuleCalculated.Text = Conversion.Hex(CRC_Data.Calculated_Module)
                Me.dgvATETestResults.DataSource = Me._dsLinemasterSoftware.Tables("TableName")
                Me.txtSerialNumber.Select()
                Me.StatusUpdate("Finished populating form.")
            Catch ex As Exception
                Me.StatusUpdate("Failed to populate form. " & ex.Message, Color.Red)
            End Try
    
        End Sub
    Last edited by stanav; Feb 26th, 2024 at 03:07 PM.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width