App.PrevInstance of VB6

  • Thread starter Thread starter Jaime Lucci
  • Start date Start date
J

Jaime Lucci

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

Thanks.
 
This is the .Net equivalant
If Process.GetProcessesByName (Process.GetCurrentProcess.ProcessName).Length



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 : (e-mail address removed)
 
m.posseth said:
This is the .Net equivalant
If Process.GetProcessesByName
(Process.GetCurrentProcess.ProcessName).Length

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>
 
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
 
Michel,

m.posseth said:
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.
 
Thankfully, this is supposedly as simple as checking a box ("make single
instance application") in VS 2005.

m.posseth said:
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
 
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 said:
This is the .Net equivalant
If Process.GetProcessesByName (Process.GetCurrentProcess.ProcessName).Length



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 : (e-mail address removed)




Jaime Lucci said:
There is any instruction that replace the App.PrevInstance which is used
in
VB6?

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

Back
Top