I have a vb program that reacts to an event (a signal from a modem) by displaying a form. I have the following (simplified) code:
Sometimes when the event occurs the form is displayed as desired. Other times, though, it will not display but rather appears minimized in the system tray and can't be made to show. (If there's a pattern as to when it displays or doesn't display, I haven't figured it out.)Code:Public Class MainForm Dim eventOccurred As Boolean = False Sub TestLoad() Handles Me.Load .... WaitEvent() End Sub Sub WaitEvent() Do Thread.Sleep(500) 'Checks every 500 ms to see if eventOccurred has been set to True (by another subroutine). Application.DoEvents() If eventOccurred then ... Me.WindowState = System.Windows.Forms.FormWindowState.Normal Me.TopMost = True Me.Show() eventOccurred = False End If Loop End Sub End Class
How can I ensure that the form will always be displayed in a topmost window?




Reply With Quote
