timer does not work in the .exe file

I wanna let a .m script file work at intervals. So I write some test codes shown below. It works fine in MATLAB--two emails are sent. But after I package it to the .EXE file using deploytool, it doesn't work correctly -- only one test email is sent.
OS :Windows 7 Ver:MATLAB 2015b 32-bit
.net 4.0/runtime 9.0/Microsoft Windows SDK 7.1 are all installed.
%%file: exetest.m
itimer=timer('Name','myTest','TimerFcn',@timertry, ...
'Period', 5,'ExecutionMode','fixedspacing','TasksToExecute',2);
start(itimer);
%%file: timertry.m
function timertry(obj,event)
mySendMail('xxxxxx@xxx.com','test','This is a test email');
%%file: mySendMail.m
function mySendMail(tEmail,subject,content)
% a packaged function
myaddress='xxxxx@xxxx.com';
setpref('Internet','SMTP_Server','******');
setpref('Internet','E_mail',myaddress);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
setpref('Internet','SMTP_Username',myaddress);
setpref('Internet','SMTP_Password','*****');
sendmail(tEmail,subject,content);

답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 8일

0 개 추천

Your code is not waiting for the timer to execute. Your code exits right after the start(timer) . That clears the workspace, including deleting the timer.

댓글 수: 3

Mr stone
Mr stone 2016년 5월 9일
thank you very much! But how to let the timer exist in the workspace until the timer is ended by itself when it's in a .EXE file? I really cannot find related information on the web.
Walter Roberson
Walter Roberson 2016년 5월 9일
Put a uiresume in there and put a uiwait in the main routine so that it pauses until the resume is executed
Mr stone
Mr stone 2016년 5월 10일
편집: Walter Roberson 2016년 5월 10일
Thanks a lot.You've really done me a big favor.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기

질문:

2016년 5월 8일

편집:

2016년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by