On Mon, 6 May 2002 15:28:30 -0400, Curtis Koppang <[EMAIL PROTECTED]> wrote:

Oh, one more thing before I let go of this thread.
I couldn't get Pretzolds' information to work, AT FIRST. In my application
I had set the visible property to true during execution of the forms
constructor to get the app. on screen early. Be aware for future reference,
strangely enough, that causes the OnLoad method and Load event members of a
windows form to actually execute before it's contructor finishes. It makes
sense but wasn't obvious at first. Made some quick changes and everythings
working now.

Thanks,
regards......
KC




>I like it!  File that one away...
>
>We keep using the two phase construction pattern because it works on any
>platform (VB6 and Java have the same "issue") and you can pass application
>data into the second constructor.  Typically we pass some domain objects in
>which represent the current UI context.  The problem with this pattern is
>that it is not "standard" out of the box .NET.  That is, it is something
>else a person off the street has to learn about our architecture.  So if
you
>have a volitile team, that is more of a reason to stick with Pete/Petzold's
>suggestion.
>
>Later,
>curt
>
>----- Original Message -----
>From: "Peter Schroeder" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Monday, May 06, 2002 1:00 PM
>Subject: Re: [DOTNET] Close() in mainform constructor
>
>
>> KC,
>>
>> The Petzold book [1] recommends overriding the protected method OnLoad
>(page
>> 312) for doing this type of work.  This method is called before the form
>is
>> visible on screen, you can successfully call the Close method as well.
>>
>> Pete
>>
>> [1]
>>
>http://www.amazon.com/exec/obidos/ASIN/0735613702/qid=1020704369/sr=8-
1/ref=
>> sr_8_67_1/002-9329452-2169629
>>
>>
>> ----- Original Message -----
>> From: "Curtis Koppang" <[EMAIL PROTECTED]>
>> To: <[EMAIL PROTECTED]>
>> Sent: Monday, May 06, 2002 10:18 AM
>> Subject: Re: [DOTNET] Close() in mainform constructor
>>
>>
>> > I don't find this suprising.  We use a two phase construction pattern
to
>> > work around issues like this.  The constructor does stuff which gets
the
>> > class up an running (at a system level) but does not depend on many (as
>> > close to zero as possible) external dependencies.  Then you call a
>custom
>> > constructor which does the application level code - which is in ~some~
>> sense
>> > business logic.  I believe this is the model other frameworks (i.e.
MFC)
>> > have recommended.
>> >
>> > So the code which creates the form would look something like the
>> > following...
>> >
>> > class Controller
>> > {
>> >     MainForm myMainForm;
>> >
>> >     public Form GetMainForm()
>> >     {
>> >         // could throw and execption, but if it does you won't have
>class
>> >         myMainForm = new MainForm();
>> >
>> >         try
>> >         {
>> >             // do the application logic
>> >             myMainForm.SecondaryConstructor();
>> >         }
>> >         finally
>> >         {
>> >             // if it fails we need to blow away the instance
>> >             myMainForm = null;
>> >         }
>> >
>> >         return myMainForm;
>> >     } // ShowForm
>> > } // Controller
>> >
>> >
>> > Hope this helps,
>> > curt
>> >
>> >
>> > ----- Original Message -----
>> > From: "K C" <[EMAIL PROTECTED]>
>> > To: <[EMAIL PROTECTED]>
>> > Sent: Monday, May 06, 2002 8:58 AM
>> > Subject: [DOTNET] Close() in mainform constructor
>> >
>> >
>> > > In my application the constructor of the main form goes through its'
>> usual
>> > > routine, if something critical happens like a missing important file,
>I
>> > > call the Close() method of the form to quit immediately. I get a
>dispose
>> > > exception, I can't seem to quit the application while im in the
>> > > constructor. Anyone know the best way to do this?
>> > >
>> > > Thanks
>> > > KC
>> > >
>> > > You can read messages from the DOTNET archive, unsubscribe from
>DOTNET,
>> or
>> > > subscribe to other DevelopMentor lists at http://discuss.develop.com.
>> > >
>> > >
>> >
>> > You can read messages from the DOTNET archive, unsubscribe from DOTNET,
>or
>> > subscribe to other DevelopMentor lists at http://discuss.develop.com.
>>
>> You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
>> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>>
>>
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to