Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Error while evaluating TimerFcn for timer /Invalid or deleted object.

Subject: Error while evaluating TimerFcn for timer /Invalid or deleted object.

From: Nima Nikvand

Date: 6 Jan, 2013 07:54:08

Message: 1 of 3

Hello everyone,

I am using a timer in my GUI, and everything seems to be working alright. However after I close my GUI, I am receiving an error, which says:


"Error while evaluating TimerFcn for timer /Invalid or deleted object."

Here is my code for the timer which I run in OpeningFcn:

tmr = timer('Name','Reminder',...
            'Period',0.1,... % Update the time every 60 seconds.
            'TasksToExecute',inf,... % number of times to update
            'ExecutionMode','fixedSpacing',...
            'TimerFcn',{@update1,handles});
start(tmr);

and here is the update1:

function update1(hObject,eventdata,handles)
set(handles.text1,'string','');
pause(0.5);
set(handles.text1,'string',num2str(datestr(now)));
set(handles.text1,'Fontsize', 10, 'FontWeight', 'bold');
pause(0.5);


Also, I run a closing function as follows:
set(hObject, 'DeleteFcn', {@closefun,handles});
function closefun(hObject,eventdata,handles)

t = timerfindall;
if ~isempty(t)
  stop(t);
  delete(t);
  clear t;
end
end


But even if I remove the closing function compeletly I still get that error upon closing the GUI. I appreciate any help.

Subject: Error while evaluating TimerFcn for timer /Invalid or deleted object.

From: Bruno Luong

Date: 6 Jan, 2013 09:13:06

Message: 2 of 3

It is completely wasteful of calling pause in Timer callback function. Remove it and increase the period of the timer.

The timer can be killed while the callback is working. You should use try/catch to prevent the handle becomes incorrect (GUI deleted).

Bruno

Subject: Error while evaluating TimerFcn for timer /Invalid or deleted object.

From: Nima Nikvand

Date: 6 Jan, 2013 22:58:08

Message: 3 of 3

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kcbf72$nm9$1@newscl01ah.mathworks.com>...
> It is completely wasteful of calling pause in Timer callback function. Remove it and increase the period of the timer.
>
> The timer can be killed while the callback is working. You should use try/catch to prevent the handle becomes incorrect (GUI deleted).
>
> Bruno

Hello Bruno, Thanks for your comment. The pause is added to the timer function so that the display blinks. As far as the error is concerned, it somehow miraculously disappeared after a few trials. I am still wondering what caused this error.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us