PC Review


Reply
Thread Tools Rate Thread

App.PrevInstance of VB6

 
 
Jaime Lucci
Guest
Posts: n/a
 
      27th Oct 2005
There is any instruction that replace the App.PrevInstance which is used in
VB6?

Thanks.


 
Reply With Quote
 
 
 
 
m.posseth
Guest
Posts: n/a
 
      27th Oct 2005
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 : (E-Mail Removed)




"Jaime Lucci" <(E-Mail Removed)> wrote in message
news:u%(E-Mail Removed)...
> There is any instruction that replace the App.PrevInstance which is used
> in
> VB6?
>
> Thanks.
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      27th Oct 2005
"m.posseth" <(E-Mail Removed)> 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/>

 
Reply With Quote
 
m.posseth
Guest
Posts: n/a
 
      27th Oct 2005
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]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "m.posseth" <(E-Mail Removed)> 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/>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      27th Oct 2005
Michel,

"m.posseth" <(E-Mail Removed)> 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/>

 
Reply With Quote
 
Greg Burns
Guest
Posts: n/a
 
      27th Oct 2005
Thankfully, this is supposedly as simple as checking a box ("make single
instance application") in VS 2005.

"m.posseth" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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]" <hirf-spam-me-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> "m.posseth" <(E-Mail Removed)> 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/>

>
>



 
Reply With Quote
 
Jaime Lucci
Guest
Posts: n/a
 
      27th Oct 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 : (E-Mail Removed)
>
>
>
>
> "Jaime Lucci" <(E-Mail Removed)> wrote in message
> news:u%(E-Mail Removed)...
> > There is any instruction that replace the App.PrevInstance which is used
> > in
> > VB6?
> >
> > Thanks.
> >
> >

>
>



 
Reply With Quote
 
Greg Burns
Guest
Posts: n/a
 
      27th Oct 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: App.PrevInstance of VB6 Jaime Lucci Microsoft VB .NET 0 28th Oct 2005 03:10 PM
PrevInstance David de Passos Microsoft VB .NET 3 21st May 2005 07:23 PM
PrevInstance David de Passos Microsoft Dot NET Framework 1 21st May 2005 05:43 PM
Previnstance function Tom Edelbrok Microsoft VB .NET 3 12th Apr 2005 06:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:03 PM.