Ah me! When I am debugging I often keep a 'doNothing' method around to
basically replace another method if I want to temporarily disable it. It
turns out that the 'doNothing' method actually works fine, but the
method it was standing in for demonstrates my problem. This indeed
points to a problem with my code in the original routine. Sorry for my
confusion.
The mystery is that I can step through the original method code (in C#
Express edition) and does exactly what I accused the 'doNothing' routine
of doing, in that it appears to 'return' normally to the event handler,
but when the event handler exits, the application closes (via a
'Dispose'). There appears to be no 'unhandled exception' or if there is,
I do not see it.
Sorry to have troubled you. Looks like I need to dig a little deeper.
Cheers,
Cliff
Peter Bromberg [C# MVP] wrote:
If the "whole application closes" there was most likely an unhandled
exception caused by the code in the "doNothing" method call, not anything
having to do with the event handler method code.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com
"Enkidu" wrote:
>I've not much experience of C#, so maybe someone can help me with this
little problem?
I've discovered that an event handler seems to be able to call methods
in its own class, but not in other classes even if they are 'in scope'
(if that is the correct term).
For instance:
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Do nothing!";
Program.pgm.doNothing();
}
If the 'doNothing' line is commented the method changes the text of the
label on clicking the button. If the 'doNothing' line is included the
program compiles but when the method is executed (as evidenced by
stepping through it), but on return the whole application closes, with
no errors. What am I missing?
--
Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?