Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 24th, 2012, 10:11 PM
Authorized User
 
Join Date: Oct 2012
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"
 
Old October 25th, 2012, 04:06 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
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!)
 
Old October 25th, 2012, 08:17 PM
Authorized User
 
Join Date: Oct 2012
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"
 
Old October 25th, 2012, 10:23 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
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!)





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.