Timer on form not affected by other thread with no error

J

Just_a_fan

Situation:

Timer1 on main form needs to be stopped during a thread action.

Programming in second thread:

timer1.enabled = false

Action:

1. No error
2. Timer is not stopped.

Well, thanks!

There is no .InvokeRequired available for a timer control
There is no error message
There is no action

What could be worse than nothing happening and no message saying it did
not happen? Oh, I know, a message saying "The action was not
performed." with no information about what action was not performed.

Yes, I fixed it by creating a global variable and setting it and having
the timer tick code look at the global variable to see if it should
proceed or exit. Very stupid and wasteful but, at least, it works.

There seems to be an idea that threads should not change global
variables which are to be viewed by code outside the thread but I see no
other way to proceed. Spawning a form would require the same global
because I don't want to use ShowDialog on it so the main thread UI will
continue to work.

Mike
 
G

Guest

(e-mail address removed) wrote in 4ax.com:
Timer1 on main form needs to be stopped during a thread action.

Programming in second thread:

timer1.enabled = false

Action:

1. No error
2. Timer is not stopped.

How are you getting a reference to the timer object?

The thread obviously needs to have access to the timer to stop it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top