Message box diplayed in timer.tick handler, not becoming modal

I am doing Process.start and timer.start in one function of my main form.
I am checking the status of the process started in the timer.tick handler function.
I also check the status of the process in the timer.tick handler function and depending on status display error message. But this message window is not turning out to be modal. ie. my main form can still be accessed even when the error message box is open.

My code is as below:

Friend WithEvents myTimer As System.Windows.Forms.Timer

Private Function Start_TP1(ByVal svc_name As String, ByVal start_opt As String) As Boolean

Dim startProcess As New Process

startProcess.StartInfo.FileName = "ntbstart.exe"
startProcess.Start()
myTimer.Start()

End
Function

Private Sub myTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myTimer.Tick

Dim
  objSC As New ServiceController

If objSC.Status.Equals(ServiceControllerStatus.Stopped) Then
MessageBox.Show(OSSW003(mintLang).Replace(REASON, ERROR_OPENTP1START(mintLang)),TITLE_ERROR(mintLang), MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

End
Sub

Please give me a solution to make the message box modal or provide some work around.




Answer this question

Message box diplayed in timer.tick handler, not becoming modal

  • ArifKh

    oops sorry...

    Timer runs in the same thread as the Form main thread..

    Suresh.

  • Liel

    Hi,

    try the following statement:

    ::MessageBox(AfxGetMainWnd()->m_hWnd,
    "Test",
    "Test",
    MB_OK | MB_TASKMODAL);

    Heiko

  • DOAHunterX

    I think the answer is straightforward.

    Remember Timers will fire the Timer event for each selected interval regardless of what the application is doing.I think the method Timer1_Tick must have been implemented in a seperate thread and this causes your message box not to block your form.

    Suresh.

  • Googlesyrop

    Hi,


    I guess this is happening because you are calling the messagebox on a seperate process (the thread that you are using). Im not quite sure if this could work but you may try using the Overloads Public Shared Function Show(IWin32Window, String) As DialogResult method of MessageBox. You could try passing your window handle on the first param to ensure that it stays in top of your form...

    BTW, this method is noly available in VS2005 Beta 2...



    cheers,


    Paul June A. Domag

  • Message box diplayed in timer.tick handler, not becoming modal