How to avoid duplicate running of Matlab Standalone Exe Application

4 Ansichten (letzte 30 Tage)
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 Kommentare
Suneesh
Suneesh am 10 Feb. 2014
How about renaming the output files with a unique identifier (like date/time) for each run?
Kanchibhotla Chandra Sekhar
Kanchibhotla Chandra Sekhar am 10 Feb. 2014
My main concern is not duplicate the running of same exe file rather corrupting of output files.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Friedrich
Friedrich am 10 Feb. 2014
Bearbeitet: Friedrich am 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 Kommentare
Kanchibhotla Chandra Sekhar
Kanchibhotla Chandra Sekhar am 10 Feb. 2014
[~,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 am 11 Feb. 2014
Bearbeitet: Friedrich am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by