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?
Cheers,
Cliff

Signature
Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?
AlexS - 22 Jul 2007 12:30 GMT
What doNothing does? Most probably problem is in the code of this method.
> I've not much experience of C#, so maybe someone can help me with this
> little problem?
[quoted text clipped - 20 lines]
>
> Cliff
Enkidu - 23 Jul 2007 11:36 GMT
Exactly what it says. There was originally no code between the open and
closing brackets, It now contains a bit of meaningless code!
public int doNothing()
{
int i = 3;
i++;
return i;
}
Cheers,
Cliff
> What doNothing does? Most probably problem is in the code of this method.
>
[quoted text clipped - 18 lines]
>> through it), but on return the whole application closes, with no errors.
>> What am I missing?

Signature
Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?
Peter Bromberg [C# MVP] - 22 Jul 2007 14:08 GMT
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
> I've not much experience of C#, so maybe someone can help me with this
> little problem?
[quoted text clipped - 20 lines]
>
> Cliff
Enkidu - 23 Jul 2007 11:58 GMT
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
> If the "whole application closes" there was most likely an unhandled
> exception caused by the code in the "doNothing" method call, not anything
[quoted text clipped - 26 lines]
>> stepping through it), but on return the whole application closes, with
>> no errors. What am I missing?

Signature
Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?