Closing Process minimizes my application

S

sewid

Hi!

I have a very simple windows form (Visual Basic, .NET-Framework 2.0).

This is my whole code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim myThread As New System.Threading.Thread(AddressOf
testThread)
myThread.Start()
End Sub


Public Sub testThread()
Dim myProcess As New Process
myProcess.StartInfo.Arguments = "fd806001"
myProcess.StartInfo.FileName = "D:\Tools\vncviewer.exe"
myProcess.Start()
End Sub
End Class


The vncviewer.exe ist the vncviewer, provided by Ultra VNC. When I
start the Process, everything works fine and Ultra VNC launches. When
I now close Ultra VNC, my application is in background of all open
windows. When I switch to the vncviewer proveded by RealVNC,
everything works fine and after closing the Viewer, my application got
the focus back (in foreground).

Same is with notepad++ (minimizes my application) and Windows notepad
(correct behaviour).

How can that be, that when I close the process my application is
pushed in background?

Best regards,
Sebastian
 
F

Family Tree Mike

I don't know that there is a predictable behaviour for which window becomes
active when you close any given application. Since your process start code
is isolated in a thread, that thread could wait for the process to exit, and
activate the form when that occurs.
 
K

kimiraikkonen

Hi!

I have a very simple windows form (Visual Basic, .NET-Framework 2.0).

This is my whole code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim myThread As New System.Threading.Thread(AddressOf
testThread)
myThread.Start()
End Sub

Public Sub testThread()
Dim myProcess As New Process
myProcess.StartInfo.Arguments = "fd806001"
myProcess.StartInfo.FileName = "D:\Tools\vncviewer.exe"
myProcess.Start()
End Sub
End Class

The vncviewer.exe ist the vncviewer, provided by Ultra VNC. When I
start the Process, everything works fine and Ultra VNC launches. When
I now close Ultra VNC, my application is in background of all open
windows. When I switch to the vncviewer proveded by RealVNC,
everything works fine and after closing the Viewer, my application got
the focus back (in foreground).

Same is with notepad++ (minimizes my application) and Windows notepad
(correct behaviour).

How can that be, that when I close the process my application is
pushed in background?

Best regards,
Sebastian

Hi Sebastian,
Tried with Windows notepad and closing Notepad didn't cause form
minimizing. However though it's hard to say more without seeing other
code and things related to TightVNC's behaviours, i recommend making
your form got focus again:

If i understood correctly, with using this code you'll determine that
your process has exited by "hasExited" boolean, then if your process
is exited and when your form is minimized for *some" reason, you can
make your form stay with normal window state.

' -------- Begin -------

Public Class Form1
Dim myProcess As New Process

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myThread As New System.Threading.Thread(AddressOf testThread)
myThread.Start()
End Sub

Public Sub testThread()
myProcess.StartInfo.Arguments = "fd806001"
myProcess.StartInfo.FileName = "D:\Tools\vncviewer.exe"
myProcess.Start()


End Sub

Private Sub Form1_resize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Resize

If myProcess.HasExited = True Then

If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
End If
End If
End Sub
End Class

' ------ End -------


Hope this helps,

Onur Güzel
 
S

sewid

Hi!

Thanks for your answers. I tried your solution and I think, I found
the reason. It's not your solution that fixes the problem, but the
FormBorderStyle. I selected "FixedToolWindow", that leads to the
described behaviour. When I use e.g. "FixedSingle", everything works
fine.

Best regards,
Sebastian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top