ApplicationEvents - StartupNextInstance Issue????

D

dotnetme

VB.net (VS 2005)

I have an application using single instance setting in "My Project", Having
some issuses with code I put in "StartupNextInstance" in
"ApplicationEvents"... What works is if I minimize the running application
and then try to start a 2nd instance of the application if it will restore
the minimized running application instead of loading a 2nd instance,Perfect
works as planned!! (code below)

But what doesn't work is if I add code to hide the application and put it in
the taskbar and the try to start a 2nd instance of the application it still
does't allow the 2nd instance but it fails(nothing happens, no errors) to
restore the application to the desktop and give it focus. is this because I
hide the window when it is minimized??? I would like to keep it in the
taskbar is there a solution to make it work? (code below)

Thanks for your help in advance....

dotnetme

'~~~~~~~~~~~~~~~~~~~~
'"ApplicationEvents"
Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, ByVal
e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs)
Handles Me.StartupNextInstance

Dim RunningProcesses As Process() =
Process.GetProcessesByName("Single Instance")
' SW_HIDE = 0
' SW_SHOWNORMAL = 1
' SW_NORMAL = 1
' SW_SHOWMINIMIZED = 2
' SW_SHOWMAXIMIZED = 3
' SW_MAXIMIZE = 3
' SW_SHOWNOACTIVATE = 4
' SW_SHOW = 5
' SW_MINIMIZE = 6
' SW_SHOWMINNOACTIVE = 7
' SW_SHOWNA = 8
' SW_RESTORE = 9
' SW_SHOWDEFAULT = 10
' SW_FORCEMINIMIZE = 11
' SW_MAX = 11
If (RunningProcesses.Length > 1) Then

ShowWindowAsync(RunningProcesses(0).MainWindowHandle, 1)

ShowWindowAsync(RunningProcesses(0).MainWindowHandle, 9)

End If

End Sub
'~~~~~~~~~~~~~~~~~~~~~~

'"Form1" - hide window and put in taskbar
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
If (Me.WindowState = FormWindowState.Minimized) Then
Me.Hide()
taskbar1.Visible = True
taskbar1.Text = "Single Instance"
End If
End Sub
 
B

Bill McCarthy

Hi,

The StartupNextInstance event occurs in your original application, at which
point you can use My.Forms.... etc.
 
D

dotnetme

Ohhh Very cool... I didn't realize that... dam that makes it easy... I
like this feature!

dotnetme
 
D

dotnetme

Thanks for the tip on Bills article, I saw an article similar on another
site... but my application is small and it runs on a users local machine,
not on a server and not remoting... really if they open more then one it
will not harm anything but I felt it looks better then having multiples open
or poping up a msgbox saying it is aready running, plus it was a good
learning experince for me... it is much cleaner now that it is a single
instance... I will consider try to get the changes Bills sugguest for 2005
to run for a learning experince as well... I enjoy it...

Thanks
 

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