testing if Form is active
I have a thread timer that works and calls a sub below, what I want the sub to do is refresh the form for the user. The issue I have is if the form isn't in focus (say the screensaver kicked on or you bring up another program or something) then the code crashes.
When the timer expires it calls this sub
Shared Sub CheckStatus(ByVal State As Object)
Dim myform As Form
myform = frmMain.ActiveForm
'MessageBox.Show("I am refreshed")
myform = Nothing
the problem is if frmMain is not the active form (because of screen saver or whatever) then myform doesn't get set and crashes when it tries to refresh it.
My question is how can I test if frmMain is active and if it is refresh it if not go on doing whatever?
Well, i'm a C# person, but just do a try and catch. If it fails, you know it's not active.
That worked so it wouldn't crash but is there a more elegant way to handle if the form is active?
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center