Solution to the reflection method to close the form and report an error

Source: Internet
Author: User

When you launch a function, if the function contains Form. Close () for the current Form, an error may be reported at Application. Run.

For this reason, I found the problem during disassembly tracking. The original function is as follows:

Code Private void navbarcontrolincludoubleclick (object sender, EventArgs e)
{
If (navBarControl1.PressedLink! = Null)
{
String itemname = navBarControl1.PressedLink. ItemName;
This. _ dynamicHelper. Methods. Invoke (itemname + "_ DoubleClicked", DynamicHelperBase. InstanceBindingFlags );
}
}

 

This function calls the corresponding function of the current form based on its ItemName for a series of navigation.

However, an error is thrown when you exit the navigation. The reason is that this. _ dynamicHelper. methods. after Invoke, The navbarcontrolpolicdoubleclick function will be returned, but the current form has been released before. At this time, the function is an invalid reference. Change to the following to solve the problem:

Code Private void navbarcontrolincludoubleclick (object sender, EventArgs e)
{
If (navBarControl1.PressedLink! = Null)
{
String iname = navBarControl1.PressedLink. ItemName;
This. BeginInvoke (new Action <string> (itemname) =>
{
This. _ dynamicHelper. Methods. Invoke (itemname + "_ DoubleClicked", DynamicHelperBase. InstanceBindingFlags );
}), Iname );
}
}

 

Related Article

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.