Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 24th, 2012, 10:11 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default Lesson 9 Try It error

I encountered a problem while playing with the program.

The buttons all work and open the forms as they should, however, when i close a form I opened and then click to open it again, i get an error.

I checked the Try It from Lesson 9 downloaded from the Wrox site and it has the error too.

Code:
 public Form1()
        {
            InitializeComponent();
        }

        //the remote forms
        GettingThereForm theGettingThereForm;
        GettingAroundForm theGettingAroundForm;
        LodgingForm theLodgingForm;
        FunStuffForm theFunStuffForm;

        private void Form1_Load(object sender, EventArgs e)
        {
            //initialise the form variables but dont display them

            theGettingThereForm = new GettingThereForm();
            theGettingAroundForm = new GettingAroundForm();
            theLodgingForm = new LodgingForm();
            theFunStuffForm = new FunStuffForm();

        }
        
        private void btnGettingThere_Click(object sender, EventArgs e)
        {
            //On button Click, open the form

            theGettingThereForm.Show();

        }
I cant post an image of the error, but it said:

ObjectDisposedException was Unhandled
Cannot access a disposed object
Object name: GettingThereForm

Troubleshooting Tip:
Make sure you have not release a resource before attempting to use it.


What does this mean?? Is it caused by the forms being initialised outside the click handler?

Perhaps this is something that will be covered in later chapters, but I thought i should let you know about the error in case someone else wonders what is going on.
__________________
"These pretzels are making me thirsty"
  #2 (permalink)  
Old October 25th, 2012, 04:06 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

I'm pretty sure this is fixed in the next lesson. (Let me know if it isn't. I don't have a copy of the book handy so I can't check right now.)

The problem is that if you click the X button on the form's upper right corner, the form is destroyed. Later when you try to display it again, it is gone.

This is related to creating the form outside of the Click event handler. The program only creates one instance of the form and tries to reuse it. That will be useful later but for now it gives you this problem.

The solution (which I hope is coming up soon) is to hide the form instead of destroying it. Then when you need it again you can redisplay it. That saves a little time but more importantly lets the form retain whatever values it had in its controls when it was hidden so when it redisplays it shows the user the previous choices.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old October 25th, 2012, 08:17 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thanks

Thanks, I figured it was something to do with being initialised outside the click handler.

Starting Lesson 11 today, great book.
__________________
"These pretzels are making me thirsty"
  #4 (permalink)  
Old October 25th, 2012, 10:23 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Quote:
Starting Lesson 11 today, great book.
Thanks! Post a review when you have a chance.

And keep posting when you get stuck!
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 8 Try It Error Luthios BOOK: Java Programming 24-Hour Trainer by Yakov Fain 6 June 11th, 2012 11:52 AM
Lesson 8 - Try It Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 February 12th, 2012 08:44 AM
Lesson 13 Try it error alawode BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 January 27th, 2012 08:32 PM
Lesson 4 Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 0 November 25th, 2011 10:25 AM
Lesson 6 Try It zavodney BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 2 June 6th, 2011 10:07 PM



All times are GMT -4. The time now is 10:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.