By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

Closing Process minimizes my application

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

"sewid" wrote:
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
Jun 27 '08 #2

P: n/a
On Apr 24, 1:57 pm, sewid <sebastian.widm...@gmail.comwrote:
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

Jun 27 '08 #3

P: n/a
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

On 24 Apr., 13:54, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Apr 24, 1:57 pm, sewid <sebastian.widm...@gmail.comwrote:
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
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.