occasional bug

  • Thread starter Thread starter nicksjacobson
  • Start date Start date
N

nicksjacobson

Try getting this bug to occur!

Run the following code in debug mode (i.e. hit F5). Then literally
just keep moving the mouse around in the main window form area (the big
gray box).

IT TAKES OVER A MINUTE, even! But *eventually*, a window pops up with
the error message:

"An unhandled exception of type 'System.NullReferenceException'
occurred in Unknown Module.

Additional information: Object reference not set to an instance of an
object."


Here's the code:
<<
using System;
using System.Drawing;
using System.Windows.Forms;

class MainForm : Form
{
public static void Main() { Application.Run(new MainForm()); }
public MainForm()
{
OpenFileDialog dlg = new OpenFileDialog();
}
}
Note: if you can even get this bug to happen, please post that you did
so. I need confirmation that it's not just my system. ;P I'm running
Win XP Pro SP2 and VS.NET 2003.

Thanks!

--Nick
 
Yes it happens on my machine also

Try getting this bug to occur!

Run the following code in debug mode (i.e. hit F5). Then literally
just keep moving the mouse around in the main window form area (the big
gray box).

IT TAKES OVER A MINUTE, even! But *eventually*, a window pops up with
the error message:

"An unhandled exception of type 'System.NullReferenceException'
occurred in Unknown Module.

Additional information: Object reference not set to an instance of an
object."


Here's the code:
<<
using System;
using System.Drawing;
using System.Windows.Forms;

class MainForm : Form
{
public static void Main() { Application.Run(new MainForm()); }
public MainForm()
{
OpenFileDialog dlg = new OpenFileDialog();
}
}

Note: if you can even get this bug to happen, please post that you did
so. I need confirmation that it's not just my system. ;P I'm running
Win XP Pro SP2 and VS.NET 2003.

Thanks!

--Nick
 
And I also get it.

My configuration is Win XP Pro SP2 and VS.NET 2003.

Michael
 
Nick,
You may need to mark Main as [STAThread] to get a message pump running
for the dialog otherwise the default would be a MTA threading model and you
wouldn't have a message pump.
The following will show a blank form on the screen. I haven't checked
to see if it leaks any memory as the dialog isn't disposed of using this
code.
------------------------------snip--------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Test
{
public class Form1 : System.Windows.Forms.Form
{

public Form1()
{

OpenFileDialog dlg = new OpenFileDialog();

}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}

------------------------------snip--------------------------------------------------

Ron Allen
 
Curious,but the following code does not result in this error:

using System;
using System.Drawing;
using System.Windows.Forms;

class MainForm : Form
{
public static void Main() { Application.Run(new MainForm()); }
public MainForm()
{

this.AutoScaleBaseSize=new Size(5,20);
OpenFileDialog dlg = new OpenFileDialog();
}
}
 
Ron,

This is not true, message pumps are 'initiated' by the Application.Run call,
STAThread or MTAThread has nothing to do with message pumps, they are meant
to put the thread running Main() in a STA or MTA which is a COM imposed
requirement.

Willy.

Ron Allen said:
Nick,
You may need to mark Main as [STAThread] to get a message pump running
for the dialog otherwise the default would be a MTA threading model and
you wouldn't have a message pump.
The following will show a blank form on the screen. I haven't checked
to see if it leaks any memory as the dialog isn't disposed of using this
code.
------------------------------snip--------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Test
{
public class Form1 : System.Windows.Forms.Form
{

public Form1()
{

OpenFileDialog dlg = new OpenFileDialog();

}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}

------------------------------snip--------------------------------------------------

Ron Allen
Try getting this bug to occur!

Run the following code in debug mode (i.e. hit F5). Then literally
just keep moving the mouse around in the main window form area (the big
gray box).

IT TAKES OVER A MINUTE, even! But *eventually*, a window pops up with
the error message:

"An unhandled exception of type 'System.NullReferenceException'
occurred in Unknown Module.

Additional information: Object reference not set to an instance of an
object."


Here's the code:
<<
using System;
using System.Drawing;
using System.Windows.Forms;

class MainForm : Form
{
public static void Main() { Application.Run(new MainForm()); }
public MainForm()
{
OpenFileDialog dlg = new OpenFileDialog();
}
}

Note: if you can even get this bug to happen, please post that you did
so. I need confirmation that it's not just my system. ;P I'm running
Win XP Pro SP2 and VS.NET 2003.

Thanks!

--Nick
 
Back
Top