[Solved] make a rectangle move in a different thread? [closed]


You are using the wrong timer. The System.Windows.Forms.Timer is made to run on the UI thread.

This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing.

Your rectangle is not drawn because the Tick event is never fired!

Solution: Use instead a timer that is made to run in the background:

System.Timers.Timer is a possible cadidate. Change our code simply to this:

void threadmethod()
{
    System.Timers.Timer t = new System.Timers.Timer();
    t.Enabled = true;
    t.Interval = 100;
    t.Elapsed += T_Tick;
    t.AutoReset = true;
}

and the rest can remain as it is and you can see your blue rectangle creep over your GUI surface

1

solved make a rectangle move in a different thread? [closed]