Found one. Bug about focus when dynamically loading controls in net

Source: Internet
Author: User
Tags net bug
Dynamic | load | The control today writes a system framework to use the dynamic loading, when debugging discovers the program often can appear the deadlock the situation, and when the deadlock also will open a "Windowsformsparkingwindow" the background process, Ran to the internet for half a day on the Windowsformsparkingwindow of information, the results of an article in Chinese did not find, there are a few flies, to the PowerWord fee Dickens has not seen a way to. Then simply create a new project, only wrote a few lines of code, the results of the operation found that there will be a death shrink:

1. Create a new Windows application

2, add a UserControl, named UserControl1,

3, add a control in the UserControl1, any control, as long as you can get the focus of the line (Label, panel, etc.)

4. Add a method to the UserControl1.cs test:

public void Test ()
{
MessageBox.Show ("This is a test!");
}

5, in the Form1.cs to add a class-level variable: private UserControl1 curobj;

6, add a panel in the Form1, named Panel1

7, add a menu in Form1, and add two menu items, named Menuitemadd and menuitemmsg;

8, in the menu item Menuitemadd Click event to add code:

Panel1. Controls.clear ();

Curobj = new UserControl1 ();

Panel1. Controls.Add (Curobj);

9, in the menu item Menuitemmsg Click event to add code:

if (curobj!= null)

Curobj.test ();



To run the program, click Menuitemadd, Menuitemmsg, Menuitemadd, menuitemmsg; Note: Do not click Other places in the middle of these operations, found that no, after the second MessageBox dialog box popped up after the program died, With ALT + TAB, you find a list of things called "Windowsformsparkingwindow".

It was later found that the program would not die after the first click on the Menuitemmsg pop-up dialog box UserControl1 or add a control in Form1 that could be focused on, or in Panel1. Controls.Add (curobj); After adding a curobj.focus (), the problem can also be solved, I think it should be in the second dynamic loading because of the first Panel1 object destroyed, the form also has no focus, after the second pop-up dialog box, The system cannot find the focus of the currently active form, so the program will die, and it will not be a problem when we click the mouse or place it in the program.

Think about it, although the problem is solved, I always feel that although I am writing the program should indeed be in the dynamic loading object after the focus, but even if I missed,. NET again how to say also should not do nothing to let system die and get a baffling windowsformsparkingwindow? Should you at least help me fix it or throw an exception? I think it's kind of. NET bug, has been fed back to Microsoft, see http://www.mscommunity.com/communitywish/ViewWish.aspx?WishID=25990, hope that the next version of Microsoft will be able to get rid of it.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.