Native exception with asynchronous Tacke-stack

P

.pd.

Hello,

In an effort to speed up form loading, I modified Chris Tacke's FormStack
example in these ways:

-- Added 2 ManualResetEvents to the StackForm class - Create and
InitComp.
-- Added a ManualResetEvent to the FormStack class - preLoadDone.
-- Added a Flip method to the FormStack class which would push a form
onto the stack and pop the previous top one.
-- Add a bool to the Push() method arg list - if true, form creation is
done in a thread. I set the Create event when complete. Once PreLoad
has instantiated the form, preLoadDone is set indicating that Push() may
safely return the address of the new form.

From Main, I push 1 synchronous form on the stack and then push a 2nd
asynchronous form.

The first form has a button on it whose click event waits for the 2nd's
form's Create event and then calls the stack Flip method for them to
change places.

Form2's Load event tries to add a button to itself and there's an
ArgumentException. When I try to examine anything in the debugger,
VS.NET 2003 hangs and I get a NativeException thrown in the PPC 2003
emulator.

I'm still quite new to all this so I probably am doing something wrong
but for managed code to be crashing in this way, I can't escape the
suspicion the bug lies elsewhere.

My short, complete example VS.NET 2003 solution can be downloaded here:

https://plus.xdrive.com/s/9582618402HPfL3vYgbozwsVuyQQ?partner=plus

And any help would be very much appreciated,

Cheers,
..pd.
 
C

Chris Tacke, eMVP

I've not looked at the code, but if you're using a thread to asynchronously
load the Form that may be a problem. UI changes off the primary thread can
cause problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top