UI thread responds to messages even though it is blocked by message box

My observation is that many times developer assume that when a message box is getting displayed then UI thread is just blocked. And UI thread cannot do anything else.

However this is not true, UI thread do respond to low level messages that are being received via mechanisms like timer event, graphics drawing etc.

To demonstrate this to one of my colleague, I came up with following approach for windows form environment

  1. In WinForms app added a timer that runs on a separate thread and notifies every two seconds
  2. Displayed message box when timer event is received
  3. Note that user cannot do anything on the form when message box is being displayed, however Form do respond to message pump messages

This is also true for a WPF application.

Multiple message box displayed on same thread

So question remains when should we consider that UI thread (or any thread per say) is blocked?

And simple answer is – a thread cannot process any other request till it is executing some form of code and not waiting on something.