How to avoid duplicate running of Matlab Standalone Exe Application

3 次查看(过去 30 天)
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 个评论
Suneesh
Suneesh 2014-2-10
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.

请先登录,再进行评论。

采纳的回答

Friedrich
Friedrich 2014-2-10
编辑:Friedrich 2014-2-10
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 个评论
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 2014-2-11
编辑:Friedrich 2014-2-11
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by