My first advice is:
don't make anything blinking! Most users will be highly irritated by this.
If you don't want to listen to this good friendly advice, better use a separate thread with
Thread.Sleep
. At least don't use
System.Windows.Forms.Timer
. Due to low priority (fool-proof feature, I think), it is so inaccurate that your blinking won't even look periodic sometimes. Better use other types of timers.
The problem is this: with those other timers and thread, you will have to notify the UI thread form non-UI thread to change color or visibility of some control to blink, etc. But 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[
^].
Wait a minute! How about
LongRunningMethod
? Oh no! You are about to commit a crime (against yourself, I guess). Never ever run anything "long running" in the UI thread. Do it in the separate thread, and also use invocation.
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[
^].
—SA