Home All Groups Group Topic Archive Search About
Author
21 Sep 2005 2:43 AM
Katie
If the program is already execute 1 instance, it will not run 2nd instance?
thanks

Author
21 Sep 2005 3:20 AM
Michael C
"Katie" <Katie@question> wrote in message
news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
> If the program is already execute 1 instance, it will not run 2nd
> instance?
> thanks

www.buygold.net, download the forwardcommandline tip-o-the-month.

Show quoteHide quote
>
>
Author
21 Sep 2005 4:19 AM
Jim Carlock
Hi Michael,

Just want to point out some problems...

1) The project might have problems compiling,
2) One of the source files contains a missing Option Explicit,
3) The .vbw files are not needed in the download,
4) The Source Safe file is not needed,
5) The executable is not needed.

Tom Esh provided some help in the past to me involving using
a mutex to limit an app to one instance.

The code in the following thread works well. And there's some
small talk about using a mutex and the definitions.

http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_frm/thread/44d4e6066e777050/700bc3524f0b7e81

Hope this helps Katie and Michael. ;-)

--
Jim Carlock
Post replies to the newsgroup, thanks.

"Michael C" <mculley@NOSPAMoptushome.com.au> wrote:
"Katie" <Katie@question> wrote:
> If the program is already execute 1 instance, it will not run 2nd
> instance?
> thanks

www.buygold.net, download the forwardcommandline tip-o-the-month.
Author
21 Sep 2005 11:23 PM
Michael C
"Jim Carlock" <anonymous@localhost> wrote in message
news:ObKgiOmvFHA.724@TK2MSFTNGP14.phx.gbl...
> Hi Michael,
>
> Just want to point out some problems...
>
> 1) The project might have problems compiling,
> 2) One of the source files contains a missing Option Explicit,
> 3) The .vbw files are not needed in the download,
> 4) The Source Safe file is not needed,
> 5) The executable is not needed.

I'll have a look at it although there shouldn't be any problems to get it
working. The code works quite well in one of my released c# apps. The good
thing about it is that if the second instance was called with command line
args these are sent onto the running app. I have updated it since because
one of the dot net functions GetMainWindowHandle didn't always return the
correct window but this shouldn't affect the vb6 version.

Michael
Author
21 Sep 2005 3:44 AM
Someone
Use:

Public Sub Main()
If Not App.PrevInstance Then
    Form1.Show
End If
End Sub

Set your startup object to Sub Main in the Project's properties. Sub Main
must be in a standard module, like Module1.


Show quoteHide quote
"Katie" <Katie@question> wrote in message
news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
> If the program is already execute 1 instance, it will not run 2nd
> instance?
> thanks
>
Author
28 Sep 2005 8:39 AM
Katie
It does not work.
When i compile it and try double click to create the 2nd instance, it still
start a new instance...



"Someone" <nob***@cox.net> wrote in message
news:NG4Ye.44166$ct5.14151@fed1read04...
Show quoteHide quote
> Use:
>
> Public Sub Main()
> If Not App.PrevInstance Then
>    Form1.Show
> End If
> End Sub
>
> Set your startup object to Sub Main in the Project's properties. Sub Main
> must be in a standard module, like Module1.
>
>
> "Katie" <Katie@question> wrote in message
> news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
>> If the program is already execute 1 instance, it will not run 2nd
>> instance?
>> thanks
>>
>
>
Author
28 Sep 2005 10:25 AM
George Bashore
Katie try this

Private Sub Main()
If Not App.PrevInstance Then
Form1.Show
Else
MsgBox "This program is already running", , "User Error"
Unload Me
End If
End Sub

Private Sub Form_Load()
Call Main
End Sub






Show quoteHide quote
"Katie" <Katie@question> wrote in message
news:uLOIHhAxFHA.2960@tk2msftngp13.phx.gbl...
> It does not work.
> When i compile it and try double click to create the 2nd instance, it
> still start a new instance...
>
>
>
> "Someone" <nob***@cox.net> wrote in message
> news:NG4Ye.44166$ct5.14151@fed1read04...
>> Use:
>>
>> Public Sub Main()
>> If Not App.PrevInstance Then
>>    Form1.Show
>> End If
>> End Sub
>>
>> Set your startup object to Sub Main in the Project's properties. Sub Main
>> must be in a standard module, like Module1.
>>
>>
>> "Katie" <Katie@question> wrote in message
>> news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
>>> If the program is already execute 1 instance, it will not run 2nd
>>> instance?
>>> thanks
>>>
>>
>>
>
>
Author
30 Sep 2005 2:02 AM
Katie
Thanks it work!
Just some input that unload me need to be comment to run smooth.

Show quoteHide quote
"George Bashore" <gbash***@bcpl.net> wrote in message
news:OsxLOcBxFHA.3256@TK2MSFTNGP09.phx.gbl...
> Katie try this
>
> Private Sub Main()
> If Not App.PrevInstance Then
> Form1.Show
> Else
> MsgBox "This program is already running", , "User Error"
> Unload Me
> End If
> End Sub
>
> Private Sub Form_Load()
> Call Main
> End Sub
>
>
>
>
>
>
> "Katie" <Katie@question> wrote in message
> news:uLOIHhAxFHA.2960@tk2msftngp13.phx.gbl...
>> It does not work.
>> When i compile it and try double click to create the 2nd instance, it
>> still start a new instance...
>>
>>
>>
>> "Someone" <nob***@cox.net> wrote in message
>> news:NG4Ye.44166$ct5.14151@fed1read04...
>>> Use:
>>>
>>> Public Sub Main()
>>> If Not App.PrevInstance Then
>>>    Form1.Show
>>> End If
>>> End Sub
>>>
>>> Set your startup object to Sub Main in the Project's properties. Sub
>>> Main must be in a standard module, like Module1.
>>>
>>>
>>> "Katie" <Katie@question> wrote in message
>>> news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
>>>> If the program is already execute 1 instance, it will not run 2nd
>>>> instance?
>>>> thanks
>>>>
>>>
>>>
>>
>>
>
>
Author
28 Sep 2005 12:28 PM
Ralph
Show quote Hide quote
"Katie" <Katie@question> wrote in message
news:uLOIHhAxFHA.2960@tk2msftngp13.phx.gbl...
> It does not work.
> When i compile it and try double click to create the 2nd instance, it
still
> start a new instance...
>
>
>
> "Someone" <nob***@cox.net> wrote in message
> news:NG4Ye.44166$ct5.14151@fed1read04...
> > Use:
> >
> > Public Sub Main()
> > If Not App.PrevInstance Then
> >    Form1.Show
> > End If
> > End Sub
> >
> > Set your startup object to Sub Main in the Project's properties. Sub
Main
> > must be in a standard module, like Module1.
> >
> >
> > "Katie" <Katie@question> wrote in message
> > news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
> >> If the program is already execute 1 instance, it will not run 2nd
> >> instance?
> >> thanks
> >>


Use a Mutex.
Here is one way...
http://www.vbaccelerator.com/home/VB/Code/Libraries/Shell_Projects/Registering_File_Associations/article.asp

Here is another...
http://vbusers.com/code/codeget.asp?ThreadID=275&PostID=1&NumReplies=0

-ralph
Author
30 Sep 2005 2:01 AM
Katie
Comparatively Mutex seems more complex...
Any advantage against previnstance?

Hope to discuss further of it.

Show quoteHide quote
"Ralph" <nt_consultin***@yahoo.com> wrote in message
news:TbadnW_o7MbwEafeRVn-jg@arkansas.net...
>
> "Katie" <Katie@question> wrote in message
> news:uLOIHhAxFHA.2960@tk2msftngp13.phx.gbl...
>> It does not work.
>> When i compile it and try double click to create the 2nd instance, it
> still
>> start a new instance...
>>
>>
>>
>> "Someone" <nob***@cox.net> wrote in message
>> news:NG4Ye.44166$ct5.14151@fed1read04...
>> > Use:
>> >
>> > Public Sub Main()
>> > If Not App.PrevInstance Then
>> >    Form1.Show
>> > End If
>> > End Sub
>> >
>> > Set your startup object to Sub Main in the Project's properties. Sub
> Main
>> > must be in a standard module, like Module1.
>> >
>> >
>> > "Katie" <Katie@question> wrote in message
>> > news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
>> >> If the program is already execute 1 instance, it will not run 2nd
>> >> instance?
>> >> thanks
>> >>
>
>
> Use a Mutex.
> Here is one way...
> http://www.vbaccelerator.com/home/VB/Code/Libraries/Shell_Projects/Registering_File_Associations/article.asp
>
> Here is another...
> http://vbusers.com/code/codeget.asp?ThreadID=275&PostID=1&NumReplies=0
>
> -ralph
>
>
Author
30 Sep 2005 2:30 AM
Jim Carlock
"Katie" <Katie@question> wrote:
> Comparatively Mutex seems more complex...
> Any advantage against previnstance?
>
> Hope to discuss further of it.

Test it out...
1) Create the app using PrevInstance model.
2) Next copy the app and paste it so you get two different
app's, one named App.exe and one named "Copy of App.exe".
3) Start each of the apps up.

4) Next, copy the "Copy of App.exe" to another folder and
rename it to "App.exe".
5) Test the results out again and see what happens.

6) Rename the copy to some other names and test it again.

It will be self-explanatory once you see what happens when
using PrevInstance.

After you've completed those test with PrevInstance, try that
while using a mutex.

Hope that helps.

--
Jim Carlock
Post replies to the newsgroup, thanks.
Author
30 Sep 2005 2:40 AM
Ralph
Show quote Hide quote
"Katie" <Katie@question> wrote in message
news:%235YXwLWxFHA.1148@TK2MSFTNGP11.phx.gbl...
> Comparatively Mutex seems more complex...
> Any advantage against previnstance?
>
> Hope to discuss further of it.
>
> "Ralph" <nt_consultin***@yahoo.com> wrote in message
> news:TbadnW_o7MbwEafeRVn-jg@arkansas.net...
> >
> > "Katie" <Katie@question> wrote in message
> > news:uLOIHhAxFHA.2960@tk2msftngp13.phx.gbl...
> >> It does not work.
> >> When i compile it and try double click to create the 2nd instance, it
> > still
> >> start a new instance...
> >>
> >>
> >>
> >> "Someone" <nob***@cox.net> wrote in message
> >> news:NG4Ye.44166$ct5.14151@fed1read04...
> >> > Use:
> >> >
> >> > Public Sub Main()
> >> > If Not App.PrevInstance Then
> >> >    Form1.Show
> >> > End If
> >> > End Sub
> >> >
> >> > Set your startup object to Sub Main in the Project's properties. Sub
> > Main
> >> > must be in a standard module, like Module1.
> >> >
> >> >
> >> > "Katie" <Katie@question> wrote in message
> >> > news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
> >> >> If the program is already execute 1 instance, it will not run 2nd
> >> >> instance?
> >> >> thanks
> >> >>
> >
> >
> > Use a Mutex.
> > Here is one way...
> >
http://www.vbaccelerator.com/home/VB/Code/Libraries/Shell_Projects/Registering_File_Associations/article.asp
> >
> > Here is another...
> > http://vbusers.com/code/codeget.asp?ThreadID=275&PostID=1&NumReplies=0
> >
> > -ralph
> >
> >

A Mutex certainly is more complex and the App.PrevInstance will work most of
the time.

PrevInstance can fail however, AFAIK, under two situations, 1) if there is a
delay in loading an application and the app is launch twice at close to the
same time. Say with a double-click 2) The second situation is where the app
may be launched from two different locations, or you have more than one copy
on a machine.

I have also heard of it failing if launched by two different mechanism, say
from a commandline opposed to from the windows shell (ie, Explorer), but
never ran into it myself.

If none of these situations apply to you. Then use PrevInstance. My caution
is based simply on the fact, that it does have a slight chance of  failing,
and things tend to get used in ways we never planned on once they are
released into the wild. If you use a Mutex, then no worries.

Also note the "Mutex" code is rather self-contained. Once you find a method
you like, you will just paste it in the next time. It's what I call
'steal-once' code. <g>

-ralph
Author
28 Sep 2005 10:35 PM
Michael C
"Katie" <Katie@question> wrote in message
news:uLOIHhAxFHA.2960@tk2msftngp13.phx.gbl...
> It does not work.
> When i compile it and try double click to create the 2nd instance, it
> still start a new instance...

Did you set the project startup to sub main?

Show quoteHide quote
>
>
>
> "Someone" <nob***@cox.net> wrote in message
> news:NG4Ye.44166$ct5.14151@fed1read04...
>> Use:
>>
>> Public Sub Main()
>> If Not App.PrevInstance Then
>>    Form1.Show
>> End If
>> End Sub
>>
>> Set your startup object to Sub Main in the Project's properties. Sub Main
>> must be in a standard module, like Module1.
>>
>>
>> "Katie" <Katie@question> wrote in message
>> news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl...
>>> If the program is already execute 1 instance, it will not run 2nd
>>> instance?
>>> thanks
>>>
>>
>>
>
>