Performing periodic audits and best practices
I am making a window form and want an audit task to run every 30 seconds. This audit essentially checks a number of services on remote computers and returns richtextbox status.
Current I have this running on an endless background thread and using invoker to update the richtextbox in the main form.
Is this best practice? If I made an endless loop in my main shape that would prevent any of my buttons from working, would you fix it?
I'm just wondering if every time I want to create a periodic validation check I need to create a new thread that checks the state or file or what do you have?
Edit: I looked further into the Timer class and decided to go with System Timer as it turned out to be better with a longer function. Thanks for pointing me in the right direction.
source to share
You should look into the Windows Forms Timer class . You don't need a loop in your main form. It is better to use a timer to trigger events that can be processed asynchronously on another thread.
source to share
(I am assuming this is a winform application)
Calling the main thread is the way to go. But what about using timer instead of an infinite loop? This gives you more control. And the timer function will execute its own thread on it.
It is good practice to allow lengthy work on a background thread so that the main thread can work with the UI.
source to share