Jump to content
Software FX Community

Unable to close form NET bug


User (Legacy)

Recommended Posts

hi,

We have a nasty problem. Basically, there's a bug in .NET: If a user

control-derived control is removed from another user control, it is no

longer possible to close the form containing the controls. More details and

example code can be found at http://www.jelovic.com/weblog/e41.htm

Now, we've found that this bug, or another with the same effect, manifests

itself with the ChartFX control under certain conditions. I've attached a

project to show the problem. It is an application with a form containing a

user control that contains the ChartX control.

To demonstrate the bug, compile & run the attached project, then

1 - right click on the chart and select edit title

2 - click the button. All this does is change the x axis label custom

format.

3 - try and close the form by clicking the 'X' button

The form does not close (nor is the form closing event fired). The only

option is to kill the thread.

Obviously it would be best for everyone if Microsoft made the effort to fix

this bug. But they have not done so to my knowledge, despite having known

about it since .NET RC1 was released. There is a workaround however: to

manually call OnControlRemoved() after removing the control.

I believe the problem is due to the title edit box being removed from the

chart control (though why it only manifests after setting another property

is a mystery), So I'd like to ask SoftwareFX to investigate this problem,

and if it is appropriate, add the workaround code.

cheers,

Rob

Link to comment
Share on other sites

Even though I couldn't reproduce the problem using the sample I sent, I've

seen this problem before but we were unable to find a workaround.

Recently, we discover the reason for this problem (as you did) is a bug in

the .NET Framework. Even though I have not seen any "formal" admission of

this bug in MSDN nor an "official" workaround, after googling for a while (a

lot !) we found that the cause seems to do with destroying a control while

event handlers are still attached to it.

However, the problem doesn't happen all the time so I suspect it could be

more complicated that. Even the sample posted by Dejan Jelovic doesn't fail

in my computer using the .NET Framework 1.1.

We are going to add the code to detach from all events before destroying the

control because it doesn't do any harm, however we can not guarantee that

this is going to fix the problem for good. Until MS give a formal

explanation/solution to this problem, this will remain a temporary

workaround.

This change will be included in the next SP.

--

FP

Software FX

Link to comment
Share on other sites

"SoftwareFX Support" <noreply@softwarefx.com> wrote in message

news:LwmoqM$cEHA.3152@webserver3.softwarefx.com...

> Even though I couldn't reproduce the problem using the sample I sent, I've

> seen this problem before but we were unable to find a workaround.

>

> Recently, we discover the reason for this problem (as you did) is a bug in

> the .NET Framework. Even though I have not seen any "formal" admission of

> this bug in MSDN nor an "official" workaround, after googling for a while

(a

> lot !) we found that the cause seems to do with destroying a control while

> event handlers are still attached to it.

>

> However, the problem doesn't happen all the time so I suspect it could be

> more complicated that. Even the sample posted by Dejan Jelovic doesn't

fail

> in my computer using the .NET Framework 1.1.

Ah, we're using .NET 1.0. I guess (hope!) it's been fixed in 1.1.

> We are going to add the code to detach from all events before destroying

the

> control because it doesn't do any harm, however we can not guarantee that

> this is going to fix the problem for good. Until MS give a formal

> explanation/solution to this problem, this will remain a temporary

> workaround.

>

> This change will be included in the next SP.

Cool, I look forward too it. Do you know when it will be released?

Rob

Link to comment
Share on other sites

We just fixed this problem internally so we are still doing some testing to

make sure nothing else was broken, so it will take a while to make it into

the SP (a month or so).

However, if you need this fix before that, you can contact our support dept.

and ask for a HotFix that includes this fix, this HotFix should be available

next week.

--

FP

Software FX

Link to comment
Share on other sites

bad news - I installed the hotfix and did a full rebuild, but the problem

hasn't gone away. :-(

using .NET 1.0.3705

Rob

"Rob" <spam@spam.com> wrote in message

news:5VSOz0UdEHA.3888@webserver3.softwarefx.com...

> ta. Do we need a support acount to get the hotfix?

>

> "SoftwareFX Support" <noreply@softwarefx.com> wrote in message

> news:4TLap5MdEHA.3888@webserver3.softwarefx.com...

> > Mention this:

> >

> > Issue ID : 976

> > Internal Issues Portal

> >

> > --

> > FP

> > Software FX

> >

> >

>

>

Link to comment
Share on other sites

I'm afraid for now there is nothing we can do to workaround this .NET

framework bug.

We followed the only recommendation that was possible for us to implement,

check the thread in the Microsoft Newsgroup at:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=1b6940cb.0407281325.2de1483b%40posting.google.com&rnum=2&prev=/groups%3Fq%3Dchartfx%26hl%3Den%26lr%3D%26ie%3DUTF-8%26scoring%3Dd%26selm%3D1b6940cb.0407281325.2de1483b%2540posting.google.com%26rnum%3D2

The other recommendation (calling OnControlRemoved) can not be done by us

and honestly I don't like it very much as you will be asking a form to

remove a control that is not it's child but it's descendant.

Since the bug has to do with Validation, you can force the form to close by

capturing the Closing event and setting Calcel = false. This however, will

not distinguish between this bug and a real validation error occurring in

your form, so you will now allow the form to be closed even when some

validation has failed.

The code to do this is as follows:

this.Closing += new

System.ComponentModel.CancelEventHandler(this.Form1_Closing);

private void Form1_Closing(object sender,

System.ComponentModel.CancelEventArgs e)

{

e.Cancel = false;

}

--

FP

Software FX

Link to comment
Share on other sites

> I'm afraid for now there is nothing we can do to workaround this .NET

> framework bug.

There is one more thing: As mentioned in that posting to the MS newsgroup,

you could raise a new event immediately after the control is removed. Then

I could call OnControlRemoved on my form.

I know it's nasty & kludgy, but this is a serious problem.

> Since the bug has to do with Validation, you can force the form to close

by

> capturing the Closing event

[snip]

This won't work I'm afraid - the event isn't fired.

cheers,

Rob

Link to comment
Share on other sites

In my experience, the OnControlRemoved approach does not work when the

control is deeper in the control tree.

You can actually do this already, you can attach to the ControlRemoved event

for all the Child Controls of the chart as follows:

foreach (Control control in chart1.Controls)

control.ControlRemoved += new ControlEventHandler(Form1_ControlRemoved);

Then you can do:

private void Form1_ControlRemoved(object sender, ControlEventArgs e) {

this.OnControlRemoved(e);

}

However, this didn't make any difference for me.

--

FP

Software FX

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...