Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

Event handler probs.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Enkidu - 22 Jul 2007 11:12 GMT
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?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.