Background:
I have a method that does some processing that I would like to be called over and over again. The method can take between 50 – 200 ms to complete.
Currently I have a System.Timers.Timer that calls the method when it elapses every 250 ms. I feel I I can make this more efficient by having the method “trigger” itself once it has completed.
Notes:
- Performance is key.
- Two of these methods should not be called at the same time, or overlap.
I would like avoid simply using a while loop that calls the method. It should call itself asynchronously perhaps using an event?
Question:
How can I have the method “trigger” itself once it has completed?
You could perform your
whileloop in a separate thread of execution, as long as you take the necessary multi-threading precautions with things such as locks, condition variables, wait handles, and the like.If you’re working with a WinForms application, you may want to look into using a BackgroundWorker.