LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CheckForDuplicateAppInstance

When I use the CheckForDuplicateAppInstance function with the option to ACTIVATE_OTHER_INSTANCE if a duplicate exists, the other application displays the last panel that was loaded using the LoadPanel function, not the last panel that was displayed using the DisplayPanel function as I expected.  This results in "odd" panel being displayed when the original instance of the applicaiton is activated.  
 
The code I use is:
 // Determine if this application is already running
 CheckForDuplicateAppInstance (ACTIVATE_OTHER_INSTANCE, &duplicateInstance);
 if (duplicateInstance == 1) {
     return 0;  // exit this instance
 }
If I use the same code with the first parameter set to DO_NOT_ACTIVATE_OTHER_INSTANCE, the "odd" panel is not displayed, however, if the original instance is not activated as I would want it to be.
 
Is this a "bug" in the CVI or am I doing something wrong?   I am using CVI 6.0 on XP professional service pack 2.
 
0 Kudos
Message 1 of 11
(4,913 Views)

In noticed one of the error codes for this function is:

-1 == You are running on a platform other than Windows 2000/NT/9x.

This may be a problem in your case.

Try checking duplicateInstance as shown in the following code and see if that works.

 

    if (CheckForDuplicateAppInstance (ACTIVATE_OTHER_INSTANCE, &duplicateInstance ) < 0)
    {
        return -1;
    }
    if (duplicateInstance )
    {
        return 0;
    }

 

robskii

0 Kudos
Message 2 of 11
(4,892 Views)

Thanks for the suggestion.  I tried it, but it did not make any difference.  It is better coding practice, so I left your suggesting in.  The CheckForDuplicateAppInstance function is returning 0 (success) with the duplicate instance variable is set to 1 (TRUE) as expected.  The function appears to be activating an additional panel when processing the ACTIVATE_OTHER_INSTANCE parameter.   The correct (main) panel of the original instance is activated as expected, but a child panel (that has been loaded, but never displayed in the original instance) also appears.  It would be very confusing to the user because the panel that appears is used to input data under only very specific circumstances.

By the way, I first noticed this problem in another executable and thought that the last panel loaded was being displayed, but that does not appear to be the case.  The exteraneous panel in both cases is one of several child panels of the main panel that is correctly activated by the function.  Orignal instance had been active, without any child panels displayed when the 2nd instance was exectuted, so I would expect that to be the case when it is reactivated.

Any more ideas???

0 Kudos
Message 3 of 11
(4,881 Views)
Hi, kfourroux.

You say that when the first instance is activated the main window and a very specific child window are displayed. Am I correct that the child window is not open in the first instance when it was activated by the second instance? If so, does the child window still appear at activation if it has never been opened in the first instance?
Sarah K.
Search PME
National Instruments
0 Kudos
Message 4 of 11
(4,865 Views)
In the case that I am testing, the child panel has NEVER been activated (either by DisplayPanel or InstallPopup, etc.) in either instance - it has been loaded using the LoadPanel function.   It just appears suddenly (on top of the main panel that should be displayed) when the call to CheckForDuplicateAppInstance is made.
0 Kudos
Message 5 of 11
(4,862 Views)
Hi, kfourroux.

I'm trying to replicate this behavior to determine if this is a bug (and either find a workaround or diagnose the problem). I'll post back here with what I find out.
Sarah K.
Search PME
National Instruments
0 Kudos
Message 6 of 11
(4,816 Views)

Have you been able to replicate the problem?

 

0 Kudos
Message 7 of 11
(4,744 Views)

Hello kfourroux,

To test this behavior, I created a main panel and child panel and created the following source code:

int main(void)
{
 panel1 = LoadPanel (0, "test.uir", PANEL);
 panel2 = LoadPanel (panel1, "test.uir", PANEL_2);
 DisplayPanel (panel1);
 
 if (CheckForDuplicateAppInstance (ACTIVATE_OTHER_INSTANCE, &duplicateInstance ) < 0)
    {
        DiscardPanel (panel1);
        return -1;
    }
    if (duplicateInstance )
    {
       DiscardPanel (panel1);
       return 0;
    }

 RunUserInterface();
 DiscardPanel (panel1);
}

I created an executable and ran it.  While this was running, I ran the code from CVI.  CVI switched to the already running executable without displaying the child panel.  So, I was unable to reproduce the behavior you are describing.  Am I doing something different than what you are doing?  Please let me know if there is anything else I need to do to reproduce this behavior.
 
Note: I build and ran the application using CVI 8 and the CVI 8 runtime engine.
 
Thanks
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 8 of 11
(4,715 Views)
I've looked more closely at my application and noticed I gave some incorrect info to begin with.  The display that is activated (incorrectly) when the CheckForDuplicateAppInstance (with ACTIVATE_OTHER_INSTANCE) function is called is NOT a child panel. In fact, it is a panel that is defined as ALWAYS floating (although it has never been displayed at this point).  The main panel (the one that is always displayed and the one I expect to see when the applicaiton is activated) is defined as NEVER floating.  If I change the main panel to ALWAYS floating, then it works better, but not always correctly.  If I also change the other panel to NEVER floating, it works all of the time.  However, I need the other panel to be set to ALWAYS floating, so that work-around is not a solution for me. 
 
 I've been able to replicate the problem using a small test program If you would like me to email it to you, I will.
 
I am working in CVI 6.0
 
Thanks
0 Kudos
Message 9 of 11
(4,694 Views)
Hello again kfourroux,
 
I was able to reproduce the behavior in CVI 8 by setting the panel that was previously one of the parent panels to always floating.  The fact that DisplayPanel was never called on this panel would lead me to believe that this is unexpected behavior.  I documented this behavior, and will forward it to the CVI team for further investigation.
 
Thanks for the feedback.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 10 of 11
(4,675 Views)