473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

ApplicationEvents - StartupNextInstance Issue????

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.StartupN extInstanceEventArgs)
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).MainWindowHand le, 1)

ShowWindowAsync(RunningProcesses(0).MainWindowHand le, 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

Jan 16 '08 #1
6 4821
When I say Taskbar I really mean System tray in the task bar...

"dotnetme" wrote:
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.StartupN extInstanceEventArgs)
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).MainWindowHand le, 1)

ShowWindowAsync(RunningProcesses(0).MainWindowHand le, 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
Jan 16 '08 #2
Hi,

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

"dotnetme" <do******@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
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.StartupN extInstanceEventArgs)
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).MainWindowHand le, 1)

ShowWindowAsync(RunningProcesses(0).MainWindowHand le, 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
Jan 17 '08 #3
Ohhh Very cool... I didn't realize that... dam that makes it easy... I
like this feature!

dotnetme

"Bill McCarthy" wrote:
Hi,

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

"dotnetme" <do******@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
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.StartupN extInstanceEventArgs)
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).MainWindowHand le, 1)

ShowWindowAsync(RunningProcesses(0).MainWindowHand le, 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
Jan 17 '08 #4
dgk
On Thu, 17 Jan 2008 19:59:44 +1100, "Bill McCarthy" <Bi**@NOSPAM.com>
wrote:
>Hi,

The StartupNextInstance event occurs in your original application, at which
point you can use My.Forms.... etc.
What a coincidence. Some guy named Bill McCarthy had an article on why
not to use the built-in single instance checkbox:

http://www1.visualstudiomagazine.com...torialsid=2331
Great stuff in there on named pipes.
Jan 17 '08 #5

"dgk" <dg*@somewhere.comwrote in message
news:rs********************************@4ax.com...
On Thu, 17 Jan 2008 19:59:44 +1100, "Bill McCarthy" <Bi**@NOSPAM.com>
wrote:
>>Hi,

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

What a coincidence. Some guy named Bill McCarthy had an article on why
not to use the built-in single instance checkbox:

http://www1.visualstudiomagazine.com...torialsid=2331
Great stuff in there on named pipes.
Thanks :)
Jan 18 '08 #6

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

"dgk" wrote:
On Thu, 17 Jan 2008 19:59:44 +1100, "Bill McCarthy" <Bi**@NOSPAM.com>
wrote:
Hi,

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


What a coincidence. Some guy named Bill McCarthy had an article on why
not to use the built-in single instance checkbox:

http://www1.visualstudiomagazine.com...torialsid=2331
Great stuff in there on named pipes.
Jan 21 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
7
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with...
2
by: Anthony Cuttitta Jr. | last post by:
We have an application that outputs several different graphs from data downloaded from our AS400. The application has worked without (this) issue for several months now, but just recently, the...
0
by: Kevin Spencer | last post by:
Hi all, I am working on a service that uploads METAR weather information to the National Weather Service FTP site. The service I'm authoring is hosted on a Windows 200 server, and the NWS FTP...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
0
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". ...
7
by: Spam Catcher | last post by:
Hi all, When I'm debugging my application in VS.NET 2005, the debugger intercepts all unhandled exceptions and does not break into ApplicationEvents.UnhandledException. How do I debug...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.