Search

Control.Invoke throws wrong/misleading exception by Bradley Grainger

Closed
as Won't Fix Help for as Won't Fix

6
0
Sign in
to vote
Type: Bug
ID: 523536
Opened: 1/6/2010 3:33:18 PM
Access Restriction: Public
Duplicates: 523539
0
Workaround(s)
0
User(s) can reproduce this bug
Calling System.Windows.Forms.Control.Invoke on a disposed control throws an InvalidOperationException from System.Windows.Forms.Control.WaitForWaitHandle with the exception message "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

This exception message is misleading, because the return value of Control.IsHandleCreated has nothing to do with the exception. It would be better to throw an ObjectDisposedException, since that reflects the underlying exceptional condition.
Details (expand)

Product Language

English

Version

.NET Framework 3.5

Operating System

Windows 7

Operating System Language

English

Steps to Reproduce

Create a Windows Forms project. Add a button to the main form (Form1), with the following event handler implementation:
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.Show();
form1.Close();
form1.Dispose();
form1.Invoke(new Action(() => MessageBox.Show("Hello")));
}

Run the program and click the button.

Actual Results

The application crashes (in the call to form1.Invoke) with an InvalidOperationException having the message "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

Expected Results

Calling form1.Invoke should immediately throw an ObjectDisposedException if the control has been disposed.
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey.

 

File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 1/10/2010 at 9:09 PM
Thanks for reporting the issue.

Customer feedback is a critical part of a successful, impactful product release. Unfortunately another part is the reality of schedules and the need to get the bits into production. We have evaluated the issue that you reported and it does not meet the criteria to be addressed in this release. This evaluation is carefully done and considers many aspects including fix cost, breaking changes, globalization, performance, etc.

Many customers have found it useful to discuss issues like this in the forums (http://forums.microsoft.com/msdn/default.aspx?siteid=1) where Microsoft and other members of the community can suggest workarounds.

Before we even begin work on the next release of the NET Framework release where we can make changes like this one we will devote time to address the top issues/suggestion (in terms of number of votes, lack of workarounds, etc). So please do continue to vote for this item if it is causing issues.

Thanks,
UIFx Team
Posted by Microsoft on 1/6/2010 at 9:36 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you
Sign in to post a workaround.