wxSingleInstanceChecker is fully functional on Win10 ?

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
SadE54
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Jan 15, 2021 9:36 am

wxSingleInstanceChecker is fully functional on Win10 ?

Post by SadE54 »

Hi,
We're using wxSingleInstanceChecker to check for existing instance of the application.
But according the way it's launched on win10 , a existing instance is not detected.
If a first instance is launched from the icon by double clicking on it, then it will not be detected (isrunning return false) by a second one launched using the console. The inverse will do the same.
But if the 2 instances are started from console, it's working.
Could it be linked to the save location of the lock file on windows ?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSingleInstanceChecker is fully functional on Win10 ?

Post by doublemax »

The MSW implementation doesn't use a lockfile.

What do you pass as "name" parameter?
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxSingleInstanceChecker is fully functional on Win10 ?

Post by PB »

I cannot confirm this. Using this code (wxWidgets master, static x64 build)

Code: Select all

#include <wx/wx.h>
#include <wx/snglinst.h>

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        m_checker = new wxSingleInstanceChecker("8982E339-BF01-4E66-BD92-9A281EC21E45");
        if ( m_checker->IsAnotherRunning() )
        {
            wxLogError(_("Another program instance is already running, aborting."));
            wxDELETE(m_checker); // OnExit() won't be called if we return false
            return false;
        }

        (new wxFrame(nullptr, wxID_ANY, "Test Frame"))->Show();
        return true;
    }

    int OnExit() override
    {
        delete m_checker;
        return 0;
    }

private:
    wxSingleInstanceChecker* m_checker;
}; wxIMPLEMENT_APP(MyApp);
I cannot launch the second instance, regardless of combination of console (cmd.exe) or File Explorer.

AFAIK, wxSingleInstanceChecker on MSW uses Windows API Mutex, not a lock file (path is not used). This also means that some parts of name can have special meaning, such as namespace prefixes (i.e., the part preceding the slash, if there is any). If you are not setting name and running the application under different users, that means the mutex name will not be the same with the obvious consequences..

BTW, the thread title specifically mentions Win10. Does it mean that it works as expected on older Windows versions?
SadE54
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Jan 15, 2021 9:36 am

Re: wxSingleInstanceChecker is fully functional on Win10 ?

Post by SadE54 »

We using this code :

Code: Select all

Application::Application()
    : wxApp(),
    m_singleInstance(std::make_unique<wxSingleInstanceChecker>())
{
...
}

bool Application::OnInit()
{
    if (!wxApp::OnInit()) { return false; }

    if (m_options.pid > 0)
    {
        WaitForPreviousInstance(m_options.pid);
    }

    if (m_singleInstance->IsAnotherRunning())
    {
        ActivateOtherInstance();
        return false;
    }
The full code is here : https://github.com/picotorrent/picotorr ... cation.cpp
(it's Picotorrent client hub)
For the moment I can't try on another win version :?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxSingleInstanceChecker is fully functional on Win10 ?

Post by PB »

Did you try compiling and running my code and did it work? If it did, the issue is with your code.

You are relying on wxWidgets generating the mutex name for you, using wxApp::GetAppName() and wxGetUserId(). As I wrote: did you check if the two are always the same, regardless of how you launch the application?
SadE54
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Jan 15, 2021 9:36 am

Re: wxSingleInstanceChecker is fully functional on Win10 ?

Post by SadE54 »

I will try your code asap and post the result. thx !
Post Reply