필터 지우기
필터 지우기

How to avoid duplicate running of Matlab Standalone Exe Application

조회 수: 2 (최근 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
Kanchibhotla Chandra Sekhar 2014년 2월 10일
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
Kanchibhotla Chandra Sekhar 2014년 2월 10일
[~,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