How to avoid duplicate running of Matlab Standalone Exe Application

3 views (last 30 days)
I have created a matlab exe standalone application. But If a accidentally run same exe file at any other location, it will corrupt the output files of my present running exe application. So i want to lock the running matlab exe application in view of windows task manager. If my application is "DataValidation.exe", how can i lock system for avoiding other duplicate run of my application.
If i duplicate run the application, it has to show the
msgbox("Already other application is in Progress");
and close the duplication run. How can i avoid this duplicate run..?
  2 Comments
Suneesh
Suneesh on 10 Feb 2014
How about renaming the output files with a unique identifier (like date/time) for each run?
Kanchibhotla Chandra Sekhar
My main concern is not duplicate the running of same exe file rather corrupting of output files.

Sign in to comment.

Accepted Answer

Friedrich
Friedrich on 10 Feb 2014
Edited: Friedrich on 10 Feb 2014
Hi,
you could use the DOS function tasklist:
[~,b] = system('tasklist /fi "Imagename eq DataValidation.exe"')
and post process the output. However simply renaming the application would workaround that check.
Maybe consider creating a /checking for a file in the output folder at startup of your application. So something like
If LOCK_FILE_EXIST
ABORT_START_OF_APPLICATION
ELSE
CREATE_LOCK_FILE
NORMAL_START
DELTE_LOCK_FILE_AT_THE_END
OR in the case you are familar with .NET you could use a global mutex like explained here. So porting this to MATLAB would give
mutex = System.Threading.Mutex(true,'{8F6F0AC4-B9A1-45fd-A8CF-72F04E6BDE8F}')
if mutex.WaitOne(System.TimeSpan.Zero,true)
disp('I can run')
pause(10)
mutex.ReleaseMutex();
else
disp('only one at a time')
end
Run this code in two different MATLAB at the same time and you will see that it works.
  2 Comments
Kanchibhotla Chandra Sekhar
[~,b] = system('tasklist /fi "Imagename eq DataValidation.exe"')
This code worked. But i also tried .NET code also its not working as excepted. Anyway Thanks
Friedrich
Friedrich on 11 Feb 2014
Edited: Friedrich on 11 Feb 2014
I tried the .NET code in several MATLAB version and it always worked fine. What exactly did not work for you? So basically if the IF evaluates to true you run the full code of your application. In the ELSE branch do nothing so that the started application exists right away.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!