|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How can i make sureIf the program is already execute 1 instance, it will not run 2nd instance?
thanks "Katie" <Katie@question> wrote in message
www.buygold.net, download the forwardcommandline tip-o-the-month.news:e2pRQZlvFHA.2064@TK2MSFTNGP09.phx.gbl... > If the program is already execute 1 instance, it will not run 2nd > instance? > thanks Show quoteHide quote > > 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: www.buygold.net, download the forwardcommandline tip-o-the-month."Katie" <Katie@question> wrote: > If the program is already execute 1 instance, it will not run 2nd > instance? > thanks "Jim Carlock" <anonymous@localhost> wrote in message I'll have a look at it although there shouldn't be any problems to get it 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. 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 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 > 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 >> > > 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 >>> >> >> > > 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 >>>> >>> >>> >> >> > >
Show quote
Hide quote
"Katie" <Katie@question> wrote in message Use a Mutex.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 > >> 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 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 > > "Katie" <Katie@question> wrote: Test it out...> Comparatively Mutex seems more complex... > Any advantage against previnstance? > > Hope to discuss further of it. 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.
Show quote
Hide quote
"Katie" <Katie@question> wrote in message
http://www.vbaccelerator.com/home/VB/Code/Libraries/Shell_Projects/Registering_File_Associations/article.asp
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... > > > > A Mutex certainly is more complex and the App.PrevInstance will work most of> > Here is another... > > http://vbusers.com/code/codeget.asp?ThreadID=275&PostID=1&NumReplies=0 > > > > -ralph > > > > 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 "Katie" <Katie@question> wrote in message Did you set the project startup to sub main?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... 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 >>> >> >> > >
Fluctuation of printer alignment
Database and report question Newbie: How to extract year from a Date object VB6 : Attach Event Handlers to Dynamically Generated Controls List all jpg files from folder (loop problem) Random first random number delete Missing File Export Template in VB.NET Question on printing with Snapshot from VB 6 VB6 IDE VBE Object reference |
|||||||||||||||||||||||