I am developing a Windows Forms application. I have four forms which is inherited from Baseform in another project. In all four forms I am using a label to show some transaction count based on network status. I have implemented a thread which gets the active form of application and setting up the text. The code works fine if application screen is active. If I minimize and open any other application, I am getting an null error exception.
How do I get the active form of an application?
Private Sub StartThread()
pollThread =New Thread(AddressOf PollfileStatus)
pollThread.IsBackground =True
running =True
pollThread.Start()
End Sub
Private Sub PollfileStatus()
While (running)
Try
For Each e As Control In Me.ActiveForm.Controls
If (e.Name = "pbStatus") Then
e.Invoke(New SetTextCallback(AddressOf Settext),
New Object() {e, 10})
End If
Next
Catch ex As Exception
Throw New ApplicationException(ex.Message)
End Try
Thread.Sleep(6000)
End While
End Sub