Wednesday, March 09, 2011

gui-thread-check

MonoDevelop often makes use of threads to run operations on the background. Although we make sure to invoke all GUI update methods through the main GUI thread, sometimes there is a bug and an update is done in the secondary thread, which causes all sort of random locks and crashes.
To make it easier to track down those bugs, I created a simple profiler module for Mono which can detect invocations to GTK# methods from a thread other than the main GUI thread. This module is available here:
To use it, build and install the module, and then run your application with the command:

mono --profile=gui-thread-check yourapp.exe

If the profiler is properly installed, you'll see an output like this:

*** Running with gui-thread-check ***
*** GUI THREAD INITIALIZED: 2861676352

Read more: Food for Monkeys