473,403 Members | 2,071 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,403 software developers and data experts.

App.PrevInstance of VB6

There is any instruction that replace the App.PrevInstance which is used in
VB6?

Thanks.
Nov 21 '05 #1
7 15499
This is the .Net equivalant
If Process.GetProcessesByName (Process.GetCurrentProcess.ProcessName).Length
1 Then
here is a usage example ( how i use it in a server component that i created
,,,, actually a bsiness logi remoting host )
<STAThreadAttribute()> _

Public Shared Sub Main()

' refuse to start multiple times on a system

If Process.GetProcessesByName _

(Process.GetCurrentProcess.ProcessName).Length > 1 Then

Dim result As Integer = MessageBox.Show _

("Another Instance of " & Process.GetCurrentProcess.ProcessName & " is
already running ! " & _

vbCrLf & "This is a server component and needs to run only once ", _

vbCrLf & "are you sure you want to start another instance ? ", _

MessageBoxButtons.YesNo, _

MessageBoxIcon.Question)

If result = 7 Then

Application.Exit()

End If

Else

Dim initForm As New frmMain

Application.Run()

End If

End Sub

Met vriendelijke groeten ,
kind regards,

Michel Posseth
Software developer [MCP]

"I have not failed. I've just found 10,000 ways that won't work."

Nohau systems B.V.
Division systems development
`s Gravelandseweg 398 A-C
3195 BK
Schiedam
Netherlands

Tel : + 31 (0) 10 8502812
e-mail : m.*******@nohausystems.com


"Jaime Lucci" <ja********@hotmail.com> wrote in message
news:u%****************@TK2MSFTNGP10.phx.gbl... There is any instruction that replace the App.PrevInstance which is used
in
VB6?

Thanks.

Nov 21 '05 #2
"m.posseth" <mi*****@nohausystems.nl> schrieb:
This is the .Net equivalant
If Process.GetProcessesByName
(Process.GetCurrentProcess.ProcessName).Length
1 Then


Note that the process name is not necessarily unique, and thus this approach
may fail. One common alternative is using a mutex:

How do I make sure that only one instance of my application runs at a time?
<URL:http://www.yoda.arachsys.com/csharp/faq/#one.application.instance>

Restricting Application to a Single Instance
<URL:http://www.codeproject.com/csharp/restricting_instances.asp>

Single Instance Application in VB.NET
<URL:http://www.codeproject.com/vb/net/sing_inistan.asp>

Single Instance Applications in WinForms
<URL:http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=711>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
yep ,, that is true

however the alternatives are pretty overdone in my eyes ( carefully
examined them , verry interesting thanks for the links ) especially if
you see the VB6 equivalant , ( big pro for VB6 here )

in my situation my program is called NHSACServer [ Nohau Systems
Aplication Component Server ] i believe this is a pretty strong name
i can`t inmagine that someone would go for a name like that

But you are right ,,,, it isn`t completely safe , if someone names his
apllication the same as you did you might have a problem if the user wants
to start them both at the same time and one of the two applications have the
described method implemented , and is the last one to start ( not the
first as this would not interfere ) :-) Laugh :-)
As you see i do not believe that it is such a big problem , however it
should be known to annyone who implements it,, as anything that can go
wrong will go wrong at some point and it is good to know were to start
searching in the event it does go wrong .

regards

Michel


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
"m.posseth" <mi*****@nohausystems.nl> schrieb:
This is the .Net equivalant
If Process.GetProcessesByName
(Process.GetCurrentProcess.ProcessName).Length
> 1 Then


Note that the process name is not necessarily unique, and thus this
approach may fail. One common alternative is using a mutex:

How do I make sure that only one instance of my application runs at a
time?
<URL:http://www.yoda.arachsys.com/csharp/faq/#one.application.instance>

Restricting Application to a Single Instance
<URL:http://www.codeproject.com/csharp/restricting_instances.asp>

Single Instance Application in VB.NET
<URL:http://www.codeproject.com/vb/net/sing_inistan.asp>

Single Instance Applications in WinForms
<URL:http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=711>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Michel,

"m.posseth" <mi*****@nohausystems.nl> schrieb:
however the alternatives are pretty overdone in my eyes ( carefully
examined them , verry interesting thanks for the links ) especially if
you see the VB6 equivalant , ( big pro for VB6 here )
I agree with you, but it should not be that hard to write a nice class which
encapsulates the whole functionality and makes it available as a black box.
AFAIS this is done in the Windows Application Framework which is available
for VB 2005. Sadly the .NET Framework doesn't provide a built-in mechanism
for this purpose.
in my situation my program is called NHSACServer [ Nohau Systems
Aplication Component Server ] i believe this is a pretty strong name
i can`t inmagine that someone would go for a name like that


True. It was just a warning.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
Thankfully, this is supposedly as simple as checking a box ("make single
instance application") in VS 2005.

"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
yep ,, that is true

however the alternatives are pretty overdone in my eyes ( carefully
examined them , verry interesting thanks for the links ) especially if
you see the VB6 equivalant , ( big pro for VB6 here )

in my situation my program is called NHSACServer [ Nohau Systems
Aplication Component Server ] i believe this is a pretty strong name
i can`t inmagine that someone would go for a name like that

But you are right ,,,, it isn`t completely safe , if someone names his
apllication the same as you did you might have a problem if the user wants
to start them both at the same time and one of the two applications have
the described method implemented , and is the last one to start ( not
the first as this would not interfere ) :-) Laugh :-)
As you see i do not believe that it is such a big problem , however it
should be known to annyone who implements it,, as anything that can go
wrong will go wrong at some point and it is good to know were to start
searching in the event it does go wrong .

regards

Michel


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oj**************@TK2MSFTNGP09.phx.gbl...
"m.posseth" <mi*****@nohausystems.nl> schrieb:
This is the .Net equivalant
If Process.GetProcessesByName
(Process.GetCurrentProcess.ProcessName).Length
> 1 Then


Note that the process name is not necessarily unique, and thus this
approach may fail. One common alternative is using a mutex:

How do I make sure that only one instance of my application runs at a
time?
<URL:http://www.yoda.arachsys.com/csharp/faq/#one.application.instance>

Restricting Application to a Single Instance
<URL:http://www.codeproject.com/csharp/restricting_instances.asp>

Single Instance Application in VB.NET
<URL:http://www.codeproject.com/vb/net/sing_inistan.asp>

Single Instance Applications in WinForms
<URL:http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=711>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Nov 21 '05 #6
Thanks Michael. Now I,m trying to bring to pront the running instance of the
application. For example, I have all windows minimized and I'm trying to
open my program from its shortcut and an instance of the program is running
and minimized, this instance would have to maximize and bring to the front
of the screen.
"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:eI**************@TK2MSFTNGP10.phx.gbl...
This is the .Net equivalant
If Process.GetProcessesByName (Process.GetCurrentProcess.ProcessName).Length
> 1 Then


here is a usage example ( how i use it in a server component that i

created ,,,, actually a bsiness logi remoting host )
<STAThreadAttribute()> _

Public Shared Sub Main()

' refuse to start multiple times on a system

If Process.GetProcessesByName _

(Process.GetCurrentProcess.ProcessName).Length > 1 Then

Dim result As Integer = MessageBox.Show _

("Another Instance of " & Process.GetCurrentProcess.ProcessName & " is
already running ! " & _

vbCrLf & "This is a server component and needs to run only once ", _

vbCrLf & "are you sure you want to start another instance ? ", _

MessageBoxButtons.YesNo, _

MessageBoxIcon.Question)

If result = 7 Then

Application.Exit()

End If

Else

Dim initForm As New frmMain

Application.Run()

End If

End Sub

Met vriendelijke groeten ,
kind regards,

Michel Posseth
Software developer [MCP]

"I have not failed. I've just found 10,000 ways that won't work."

Nohau systems B.V.
Division systems development
`s Gravelandseweg 398 A-C
3195 BK
Schiedam
Netherlands

Tel : + 31 (0) 10 8502812
e-mail : m.*******@nohausystems.com


"Jaime Lucci" <ja********@hotmail.com> wrote in message
news:u%****************@TK2MSFTNGP10.phx.gbl...
There is any instruction that replace the App.PrevInstance which is used
in
VB6?

Thanks.


Nov 21 '05 #7
Take a look at the second question on this page...

http://msdn.microsoft.com/msdnmag/is...s/default.aspx

It does not look like an easy undertaking. :(

Greg
"Jaime Lucci" <ja********@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Thanks Michael. Now I,m trying to bring to pront the running instance of
the
application. For example, I have all windows minimized and I'm trying to
open my program from its shortcut and an instance of the program is
running
and minimized, this instance would have to maximize and bring to the front
of the screen.

Nov 21 '05 #8

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

Similar topics

1
by: smith | last post by:
I was recently set to release an app that used very common single instance code and hit the oddest issue. After many hours of full build tests I believe that it is duplicatable. Environment: ...
3
by: Helene Day | last post by:
I am looking for the equivalent of this VB code: If App.PrevInstance Then End if Thanks, Helene (I am still learning about .NET)
8
by: Chris Thunell | last post by:
I have created a VB.net windows forms application. If I have the program running and then I mistakenly click on my desktop icon again, I get a second instance of the program running. Is there...
2
by: johnmann56 | last post by:
Hello. I have written a simple image viewer application using C# .NET. It only needs to display one image at a time. When a different program, in C, running on the same machine, does a...
9
by: Tolga Tanriverdi | last post by:
I made a gui program with c# but i want even if people double click my program more than once it would only open once is something like that possible if it is how?
4
by: Michael Passalacqua | last post by:
In VB.NET, how do you check to see if an instance of your application is already running? Michael Passalacqua Portland Community College CIS Faculty *** Sent via Developersdex...
3
by: Tom Edelbrok | last post by:
In the VB.Net documentation it says that there is no direct equivalent to VB6's 'PrevInstance' function, so they suggest making your own with the following code: Function PrevInstance() As...
3
by: David de Passos | last post by:
Hi! There is my code: Shared Function PrevInstance() As Boolean If Ubound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrent Process.ProcessName)) > 0 Then Return True...
3
by: Tom Rogers | last post by:
How do I make it so that once my application (.exe) is running, if the user tries to run a second instance of the program, it is not allowed. I want my program to be able to have only one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.