RE: Delegates & Asynchronous Callback

Tech-Archive recommends: Fix windows errors by optimizing your registry



Technically speaking, yes it could. This is because the "LongRunningProcess"
is running on a different thread and the asynchronous callback will happen on
the same thread that the "LongRunningProcess" is running on.

If the system changed threads after your call to invoke it is conceivable
that the callback could happen before the call to ShowDialog. It's very
unlikely but if it did happen it would be very hard to debug.

--
Brian Delahunty
Ireland

http://briandela.com/blog


"standogan@xxxxxxxxx" wrote:

> I have a long running process, and I use Delegates to start it, and
> during the process I want to show a wait form to the user.
>
> ///////////////////CODE/////////////////////////////////
>
> public void StartProcess()
> {
> MyDelegate del = new MyDelegate(LongRunningProcess);
> del.Invoke(new AsyncCallback(CloseWaitForm), null);
>
> waitForm.ShowDialog(this);
> }
>
> public void CloseWaitForm(IAsyncResult result)
> {
> waitForm.HideYourself();
> Application.DoEvents();
>
> AsyncResult ar = (AsyncResult) result;
> MyDelegate del = (MyDelegate)ar.AsyncDelegate;
> del.EndInvoke(ar);
> }
>
> ////////////////////////////////////////////////////////
>
> If in the LongRunningProcess() an exception occurs, and invoke ends
> (CloseWaitForm calls), can it be before the line in which I show the
> form? I mean, invoke ends and waitForm hides, before it is shown, then
> it shows up and stays there forever. Is this a possibility? If it is
> how I can avoid it?
>
> Best Regards...
>
>
.