Oh sorry, I misread.
How about doing the loading asynchronous instead then? Just disable the
elements that wont work because its still loading and use Form.Invoke to
inform the form of when it can enable the elements and load them from the
data computed? That should solve your problem, although watch out for having
the form being disposed by the time you reach the Form.Invoke call.
/Dan
[quoted text, click to view] "Dilip M" <DilipM@discussions.microsoft.com> wrote in message
news:1FAE3D1D-554A-44B3-95F2-8AC52BD2C8F2@microsoft.com...
>I don't think I explained it clearly...the form closing event does NOT
>fire.
> That is the root of my problem, since the code that I need executed is in
> that method.
>
> The loading of the form takes quite some time, and the user may close it
> before the loading has completed.
>
> "Daniel Carlsson" wrote:
>
>> Heres a (not tested) idea, main thing is that you can cancel the closing
>> of
>> a form in its Closing event.
>>
>> Sub OnLoad(...)
>> Me.Enabled = False
>> ...
>> Me.Enabled = True
>> End Sub
>>
>> Sub OnClosing(...)
>> e.Cancel = Not Me.Enabled
>> End Sub
>>
>> Hope it helps
>> /Dan
>>
>> "Dilip M" <Dilip M@discussions.microsoft.com> wrote in message
>> news:75EA5418-32FF-4451-90F8-FF26E7ADA32C@microsoft.com...
>> > Hi,
>> >
>> > I am trying to prevent a form from being closed by the user until the
>> > code
>> > in the OnLoad method executes. This code can take quite some time to
>> > complete executing. This form itself is launched from my main form
>> > using
>> > ShowDialog.
>> >
>> > I cannot use an approach like having another form showing 'Please Wait'
>> > or
>> > something to that effect.
>> >
>> > The basic problem here is that I need to run some code on the Close
>> > event
>> > of
>> > the form, which does not get executed if the user closes the form as I
>> > described.
>> >
>> > I guess another way of asking my question is whether there is any way
>> > the
>> > code in the Close event will ALWAYS get executed - some other event
>> > etc?
>>
>>
>>