[Mono-bugs] [Bug 430477] Debug.Assert() does not work in winform apps

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Sep 29 05:57:35 EDT 2008


User robertj at gmx.net added comment

Robert Jordan <robertj at gmx.net> changed:

           What    |Removed                                         |Added
                 CC|                                                |robertj at gmx.net

--- Comment #4 from Robert Jordan <robertj at gmx.net>  2008-09-29 03:57:34 MDT ---
Jon, you probably did not compile with -d:DEBUG

Steve, using MessageBox alone is a bad idea because Debug.Assert might be
from another thread. You'd need to invoke MessageBox from the main thread,
using a synchronization context:

SyncronizationContext ctx;
DialogResult result;

public GuiListener ()
    // assumes GuiListener..ctor is called from the main thread.
    SyncronizationContext ctx = SynchronizationContext.Current
        as WindowsFormsSynchronizationContext;
    if (ctx == null) throw new InvalidOperationException ();

DialogResult ShowDebugAssertMsg(string message, string detailMessage)
    result = DialogResult.Ignore;

    ctx.Send (delegate(object state) {
        result = MessageBox.Show (...)
    }, null);

    return result;

For .NET 1.1 we'd probably need to resort to Control.Invoke:

DialogResult ShowDebugAssertMsg(string message, string detailMessage)
    result = DialogResult.Ignore;

    // FIXME: is there another way to get a Control instance from the main
    Control ctl = Form.ActiveForm;
    if (ctl != null) {
        ctl.Invoke (delegate {
            result = MessageBox.Show (...)

    return result;

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list