Discussions related to Visual Prolog
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

About Preventing two instances of a program to run simultaneously

Unread post by Tonton Luc »

Hi,

Using the code from this post : http://discuss.visual-prolog.com/viewto ... 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() ?
Attachments
error_mutex.jpg
error_mutex.jpg (204.96 KiB) Viewed 6691 times
Last edited by Tonton Luc on 10 Feb 2016 9:22, edited 1 time in total.
B.Hooijenga
VIP Member
Posts: 57
Joined: 11 Jul 2002 23:01

Unread post 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

Ben
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi Ben,

Exactly what I need.
Your code works fine.

Thanks for your help. :wink:
Post Reply