Do form events occur in different Threads? For example, if I have a panel in the form in which I have the Click event and I have a keyDown event in the form and I activate the 2 events at the same time (I click on the form and press a key on the keyboard), my question is , the code that you have in the 2 events will be played at the same time? or will you just do an event? here an example
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Console.WriteLine($"{e.X} " + $"{e.Y}");
}
private void Pantalla_Click(object sender, EventArgs e)
{
Console.WriteLine($"click");
}
The events of a form occur in a single thread, which is the interface thread.
The way windows works, there is a while loop waiting for events. When an event arrives, it is processed and then returns to the while to wait for the next one.
As long as one event is not finished, the next one is not executed. So, answering your question. No, the events will not play at the same time. First one will be executed and then another.
In fact, if you start a thread inside your code and try to modify something in the interface (the color of a button for example) it will give you an exception since the interface is protected so that only the main thread can manipulate it.
An application freezes precisely because an event takes a long time to execute and subsequent interface drawing events are not executed.
There are several ways to "enhance" the response of a form, the easiest to use is to use asynchronous code since it does not involve new threads so access to the interface is safe.