Great! Excellent exercise for a beginner, almost a tradition!
First, decide what you want to use,
System.Windows.Forms
or WPF. Learn the basics of each (use Google but at first prefer the search parameter "site:Microsoft.com". One hint: use thread, not a timer and, in the thread body also use
System.DateTime
. Even with timer, always take time from this structure, never rely on timer's timing. (But avoid a timer, a thread is much easier, safer and more correct, in general; make thread body a cycle calling
System.Threading.Thread.Sleep
with the sleep time less then a second.
What else? Oh, invocation! You cannot call anything related to UI from non-UI thread. Instead, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
Same thing with timer. Better use
System.Timers.Timer
, and don't use
System.Windows.Forms.Timer
(almost never); it's unreliable in terms of accuracy but does not require invocation, already works in UI thread. For other timers, you need invocation on UI thread, as described above.
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
This beginner's work nevertheless will give you a good chunk of experience in very important .NET techniques you really want to use in most of other projects.
—SA