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 ?
wxSingleInstanceChecker is fully functional on Win10 ?
Re: wxSingleInstanceChecker is fully functional on Win10 ?
The MSW implementation doesn't use a lockfile.
What do you pass as "name" parameter?
What do you pass as "name" parameter?
Use the source, Luke!
Re: wxSingleInstanceChecker is fully functional on Win10 ?
I cannot confirm this. Using this code (wxWidgets master, static x64 build)
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?
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);
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?
Re: wxSingleInstanceChecker is fully functional on Win10 ?
We using this code :
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
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;
}
(it's Picotorrent client hub)
For the moment I can't try on another win version
Re: wxSingleInstanceChecker is fully functional on Win10 ?
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?
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?
Re: wxSingleInstanceChecker is fully functional on Win10 ?
I will try your code asap and post the result. thx !