Help needed regarding: Application.DoEvents() throws objectreference not set error

  • Thread starter Bharathi Harshavardhan
  • Start date
B

Bharathi Harshavardhan

Hi,

I have an application in which I have used Application.DoEvents()
method in the click event of a NumericUpDown. This particular method
is throwing "Object reference not set to an instance of an object"
error.. Does anyone have any idea about it?

Regards,
Bharathi
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,

I have an application in which I have used Application.DoEvents()
method in the click event of a NumericUpDown. This particular method
is throwing "Object reference not set to an instance of an object"
error.. Does anyone have any idea about it?

Regards,
Bharathi

Hi,

Can you post some code? where it's happening?

Why are you calling DoEvents?
 
M

Marc Gravell

The StackTrace and/or the nested InnerExceptions might be illuminating -
but it might also be useful to illustrate what you are trying to do with
sample code.

As Ignacio alludes; DoEvents() is not an ideal method; it has various
associated issues, most notably reentrancy. Useful in VB6 days when you
only had one thread, but usually there are cleaner ways to code in C#.

Marc
 
B

Bharathi Harshavardhan

Hi,

This is a bug with the .net numeric up/down control. Clicking on the
up/Down button on this control continously would throw Object
reference error. I have used Application.DoEvents() event in the
Click event Handler of the up/down control. This particular error
cannot be resolved currently because this is a bug with the Numeric Up/
Down control.

Bharathi
 
M

Marc Gravell

Out of interest, what makes you conclude that the up/down control is the
cause? You have broken the natural execution flow by forcing DoEvents -
I'd argue that the first thing to do is "not call DoEvents"; if it stops
erroring, then your code was the problem...

Marc
 
B

Bharathi Harshavardhan

Hi Marc,

I removed DoEvents call from Click Event Handler. Still the I could
get the obj ref error.

When we click continuously on a NumericUpDown Control, I get a null
reference exception.

System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Windows.Forms.UpDownButtons.StopTimer()
at System.Windows.Forms.UpDownButtons.EndButtonPress()
at System.Windows.Forms.UpDownButtons.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)

I read few articles related to this and got to know that this is the
Unhandled Exception in NumericUpDown Control

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=251486

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1554298&SiteId=1

Thanks,
Bharathi
 
B

Bharathi Harshavardhan

Yes. I am getting the error even after removing the DoEvents() method
call.

Thanks,
Bharathi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top