[Mono-bugs] [Bug 691525] New: Opening a form or messageBox on a seperate thread throws exception

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue May 3 16:18:36 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=691525

https://bugzilla.novell.com/show_bug.cgi?id=691525#c0


           Summary: Opening a form or messageBox on a seperate thread
                    throws exception
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.10.x
          Platform: i686
        OS/Version: Windows 7
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: valdiorn at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User
           Blocker: ---


Description of Problem:

When calling new Form(), MessageBox.Show() (and probably other methods that
create windows) from a thread other than the main thread an Exception is thrown
and the program will crash. This happens under certain conditions described
below.

Steps to reproduce the problem:

1. Open a window of any kind, on any thread, then close it.
(Make sure all previously opened windows and forms and now disposed of)
2. attempt to open another window on a thread other than the main thread, an
exception is thrown.

Actual Results:

Trying to run MessageBox.Show("") :

Unhandled Exception: System.OutOfMemoryException: Not enough memory to complete
operation [GDI+ status: OutOfMemory]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename
unknown>:0
  at System.Drawing.Graphics.FromHwnd (IntPtr hwnd) [0x00000] in <filename
unknown>:0
  at System.Windows.Forms.XplatUIWin32.GetAutoScaleSize (System.Drawing.Font
font) [0x00000] in <filename unknown>:0
  at System.Windows.Forms.XplatUI.GetAutoScaleSize (System.Drawing.Font font)
[0x00000] in <filename unknown>:0
  at System.Windows.Forms.Form.GetAutoScaleSize (System.Drawing.Font font)
[0x00000] in <filename unknown>:0
  at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0
  at System.Windows.Forms.MessageBox+MessageBoxForm..ctor (IWin32Window owner,
System.String text, System.String caption, MessageB
oxButtons buttons, MessageBoxIcon icon, Boolean displayHelpButton) [0x00000] in
<filename unknown>:0
  at System.Windows.Forms.MessageBox+MessageBoxForm..ctor (IWin32Window owner,
System.String text, System.String caption, MessageB
oxButtons buttons, MessageBoxIcon icon) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check)
System.Windows.Forms.MessageBox/MessageBoxForm:.ctor
(System.Windows.Forms.IWin32Window,
string,string,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)
  at System.Windows.Forms.MessageBox.Show (System.String text) [0x00000] in
<filename unknown>:0
  at consumerApp.Program.dialog () [0x00000] in <filename unknown>:0
  at System.Threading.Thread.StartUnsafe () [0x00000] in <filename unknown>:0

This program shows the bug:

using System;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace consumerApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Form keepAlive = new Form();

            while (true)
            {
                string input = Console.ReadLine();
                if (input == "open")
                    start();

                Console.WriteLine(input);
            }
        }

        public static void start()
        {
            Thread t = new Thread(new ThreadStart(dialog));
            t.Start();
        }

        public static void dialog()
        {
            MessageBox.Show("");
        }
    }
}

Note that uncommenting the line
//Form keepAlive = new Form();
makes the bug not show up. It only shows up after you have instantiated one or
more Forms and then disposed of them ALL. By uncommenting this line, an
instance of Form is stored and the program runs normally!

Expected Results:

MessageBox.Show("") should not throw an exception.


How often does this happen? 

Every time.

Additional Information:

To use the program:
Compile it (reference System.Windows.Forms)
type "open"
close the window
type "open" again
program crashes

Note: I tried both gmcs and VS2010 (.NET 2.0 and .NET 4.0) compilers, both give
the same results
Note: This DOES work when I run it using .net framework (I run "Program.exe"
instead of "mono Program.exe")

-- 
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