Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance
Can not always detect Previous Instance Can not always detect Previous Instance
Can not always detect Previous Instance
Go Back  Xtreme Visual Basic Talk > > > Can not always detect Previous Instance


Reply
 
Thread Tools Display Modes
  #1  
Old 04-11-2001, 11:13 AM
Neptune
Guest
 
Posts: n/a
Default Can not always detect Previous Instance


I use following to detect if my application is being loaded while a previous instance is already running

If App.PrevInstance Or FindWindow("ThunderRT6FormDC", App.Title) > 0 Then
Unload me
End If

This code is the first code snippet of the Form_Load event of my splash form. Actually if this is a second instance, before unloading itself it does a lot of work, finds the first instance window, brings it to the top of the z order,sets focus to it checks if the second running has a command line and if this is an associated file, if so, send it to the first instance who will automatically open and load the file in its interface.
But when I run the exe in instances sometimes the first app got the focus but sometimes the second loads as well.
And I ran the exe and ran another (second) instance in the VB IDE and stepped throught the code and found out that above App.PrevInstance Or FindWindow("ThunderRT6FormDC", App.Title) > 0 returns False even though there is a previous instance running.

Should I put this check in the Form_Load event of my main form instead of the splash as their captions are different ?
Or what is going on ? Actually how App.Previnstance work does it check the captions of the open windows ? or what ?

Thank you


Reply With Quote
  #2  
Old 04-11-2001, 11:39 AM
BillSoo's Avatar
BillSooCan not always detect Previous Instance BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Re: Can not always detect Previous Instance

I don't know if this helps but....

we just use app.previnstance, but we put it in a Main subroutine on a module (ie. the main sub is run first and this sub loads the forms).

We haven't had the kind of trouble you describe using this method...

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #3  
Old 04-11-2001, 11:46 AM
Dazz
Guest
 
Posts: n/a
Default Re: Can not always detect Previous Instance

Same here I use PrevInstance a bit and never had a problem.

Are you sure that it's nothing to do with the code that check the 'Command' and parses the file info and stuff?

Reply With Quote
  #4  
Old 04-12-2001, 06:02 AM
Neptune
Guest
 
Posts: n/a
Default Re: Can not always detect Previous Instance

Thank you.

The code that handles the command line comes AFTER the
App.Previnstance check. And the problem is there, it never runs.

I gave up checking this incident in the IDE as it can be misleading as I am told.
I compiled an exe. Ran first instance. Ran a second which perfectly detected itself as the second instance, shifted focus to the previous etc. and unloaded itself as the code goes.

Now, while first instance still running I double-clicked a file associated with it. Surprise !!! Splash form of the second instance gets loaded which then loaded the main form of the second instance.(As I mentioned earlier App.Previnstance is checked in the first Form_Load event of the splash form.)
So the problem is isolated to the second instance run with a command line only. As I have even added FindWindow API to find the previous instance as an added (maybe unnecessary) precaution and as it seems to fail I am very frustrated.

But..
I think I found a Windows glitch..

My executable's name is PXRun.exe
When I delete the exe and double-click run an associated file, "Program Not Found" dialog appears as expected, but telling me "Windows can not find Minus.exe" !!!!

The fact is that my program resides under a folder named "Minus 120", exact path is C 000001\Minus 120\PXRun.exe (weird huh ?). If the exe is there, windows can find it without problem. But if deleted then it breaks the name of the folder at the very first space character it comes into and mistook it as the name of the exe. Isn't it weirder than my folder names ?

Therefore, I do not trust Windows' way of handling what is happening within. I think that this is the problem as the second instance run may have it's application name as Minus and Windows interpretes it as another application.But why Windows does not get fouled if the second instance is run without a command line defies me.

I tested this oddity. I renamed the folder as "Minus120" and the problem disappeared completely.
(Same results for above incidences under Win 98 and Win NT 4.0)

Well I still test the problem in different contexts. I will let you know if I find out more that deserve consideration.


Reply With Quote
  #5  
Old 04-12-2001, 09:37 AM
turlough
Guest
 
Posts: n/a
Default Re: Can not always detect Previous Instance

Do you think it just stopped at the first space and then gave the program that name?

turlough

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance Can not always detect Previous Instance
Can not always detect Previous Instance
Can not always detect Previous Instance
 
Can not always detect Previous Instance
Can not always detect Previous Instance
 
-->