Timers.Timer and threading

Hi there,

I am currently using the System.Timers.Timer class to call an 'OnTimer' method 20 times per second. This method then makes calls into the rest of the application.

Unfortunatley, because of the way the Timer class works, the 'OnTimer' method is executed on a different thread, but this then calls other methods in the application which are not thread-safe.

Is there any way I can cause the Ontimer method to trigger an event (or equivalent) in the same thread that the rest of the application is running in? This would obviously be far simpler than attempting to make everything else threadsafe!

Any help would be much appreciated,
Stuart.

Comments

  • Hi

    Fair enough.
    You could rais events, but I am not convinced that this is the right approuch.

    Can you give me some background info please.

    Brian
  • If raising events crosses the thread-boundary then that sounds exactly the right thing to do. Can you confirm that this is the case?

    My other option is to use a Form-timer, but I'd rather not do that as in the future I may want this part of the app to run outside of a form.

    Not really sure what additional info I can give to what I said in my previous email - is there anything specific that would help?

    Many thanks,
    Stuart.

    : Hi
    :
    : Fair enough.
    : You could rais events, but I am not convinced that this is the right approuch.
    :
    : Can you give me some background info please.
    :
    : Brian
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories