method called by Delegate.BeginInvoke from form load; Sometimes executes before Form.Shown RRS feed

  • Question

  • Due to some logic we call methodA using Delegate.BeginInvoke from Form.Load method.

    Once methodA finishes we call AsyncOperation.PostOperationCompleted to close the Form;

    However sometimes Form.Shown event runs after closing the form. I see Shown event is called as BeginInvoke(new MethodInvoker(CallShownEvent));

    How to guarantee method called by delete.beginInvoke executes after Form.Shown event;

    Note I cannot move call to methodA using Delegate.BeginInvoke from Form.Load method.

    Please advice. 


    Thursday, March 19, 2020 8:35 PM

All replies

  • We need to see the code for calling and the method called.

    If you are using async/await wrong this can be the problem as this sounds like what's going on but without specific I could be offbase.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Thursday, March 19, 2020 8:44 PM