]>
git.saurik.com Git - wxWidgets.git/blob - interface/snglinst.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxSingleInstanceChecker class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxSingleInstanceChecker
13 wxSingleInstanceChecker class allows to check that only a single instance of a
14 program is running. To do it, you should create an object of this class. As
15 long as this object is alive, calls to
16 wxSingleInstanceChecker::IsAnotherRunning from
17 other processes will return @true.
19 As the object should have the life span as big as possible, it makes sense to
20 create it either as a global or in wxApp::OnInit. For
26 const wxString name = wxString::Format("MyApp-%s", wxGetUserId().c_str());
27 m_checker = new wxSingleInstanceChecker(name);
28 if ( m_checker-IsAnotherRunning() )
30 wxLogError(_("Another program instance is already running, aborting."));
32 delete m_checker; // OnExit() won't be called if we return @false
38 ... more initializations ...
51 Note using wxGetUserId to construct the name: this
52 allows different user to run the application concurrently which is usually the
53 intended goal. If you don't use the user name in the wxSingleInstanceChecker
54 name, only one user would be able to run the application at a time.
56 This class is implemented for Win32 and Unix platforms (supporting @c fcntl()
57 system call, but almost all of modern Unix systems do) only.
62 class wxSingleInstanceChecker
66 Like Create() but without
69 wxSingleInstanceChecker(const wxString
& name
,
70 const wxString
& path
= wxEmptyString
);
73 Destructor frees the associated resources.
75 Note that it is not virtual, this class is not meant to be used polymorphically
77 ~wxSingleInstanceChecker();
80 Initialize the object if it had been created using the default constructor.
81 Note that you can't call Create() more than once, so calling it if the
82 @ref wxsingleinstancechecker() "non default ctor"
83 had been used is an error.
86 must be given and be as unique as possible. It is used as the
87 mutex name under Win32 and the lock file name under Unix.
88 GetAppName() and wxGetUserId()
89 are commonly used to construct this parameter.
92 is optional and is ignored under Win32 and used as the directory to
93 create the lock file in under Unix (default is
96 @returns Returns @false if initialization failed, it doesn't mean that
97 another instance is running - use IsAnotherRunning()
100 bool Create(const wxString
& name
,
101 const wxString
& path
= wxEmptyString
);
104 Returns @true if another copy of this program is already running, @false
107 bool IsAnotherRunning();