Application Responsiveness 
by Joe Duffy

Example 1: 

MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}


Example 2: 

class MyWindow : Window {
  Button myButton = /*...*/;
  void myButton_Click(object sender, RoutedEventArgs e) {
    ThreadPool.QueueUserWorkItem(delegate {
       // Perform intensive operation
       myButton.Dispatcher.BeginInvoke(delegate {
          // Update UI element based on outcome of
          // the previous operation.
        });
    });
  }
}

1


