Page 1 of 1

About Preventing two instances of a program to run simultaneously

Posted: 9 Feb 2016 13:29
by Tonton Luc

Using the code from this post : ... ight=mutex, the following message is displaying (when a second instance of my application is started tu run).

Question : is it possible to replace this message with my own "beautiful" vpiCommonDialogs::note() ?

Posted: 9 Feb 2016 15:25
by B.Hooijenga
Hello Tonton,

I use this code for years without problems.

I do not need a note but leaving out fail should do the job

Code: Select all

constants     error_already_exists = 183. % From MSDN   class facts     okToRunMutex : mutex := erroneous.     taskwindow : taskwindow := erroneous.   class predicates     okToRun : () determ. clauses     okToRun() :-         try             okToRunMutex := mutex::createNamed("Gregorius"),             not(multiThread_native::wait_timeout = okToRunMutex:wait(1))         catch TraceId do               LastError = exception::getLastError(),               if LastError = error_already_exists                  then                          vpiCommonDialogs::note("Gregorius is al gestart"),                          fail                         % Description = common_exception::getLastErrorDescription(LastError),                          % vpiCommonDialogs::note(tostring(LastError),Description)                  else                         common_exception::continue_unknown(TraceId, classInfo, predicate_name())               end if          end try.   clauses     get_taskwindow() = taskwindow.   clauses     run():-         if okToRun() then             TaskWindow = taskWindow::new(),             taskwindow := Taskwindow,             TaskWindow:show()         end if.
Kind regards


Posted: 10 Feb 2016 9:23
by Tonton Luc
Hi Ben,

Exactly what I need.
Your code works fine.

Thanks for your help. :wink: