BeginInvoke()

Last post 07-01-2009 3:16 PM by wesleytremayne. 0 replies.

Sort Posts:

  • BeginInvoke()

    07-01-2009, 3:16 PM

    To simplify what I am doing: I have a control and I want to set it's visible property and value on seperate threads; both will be using a database transaction. When I run the code, both threads execute correctly but the page doesn't show the changes in the properties. I know I am missing some logic as I am new to this. Here is my code:


     private delegate void VisibleDelegate(object sender, EventArgs e);

     private delegate void CalculateDelegate(object sender, EventArgs e);


    PageLoad

    {

    textbox txt = new textbox();

    txt.TextChanged += new EventHandler(Calculate);

    txt.TextChanged += new EventHandler(VisibleSwitch);

    }


            private void VisibleSwitch(object sender, EventArgs e)

                {

                    VisibleDelegate ad = new VisibleDelegate(MyClass.VisibilitySwitch);

                    AsyncCallback CallbackHandler = new AsyncCallback(MyCallbackMethodVis);

                    ad.BeginInvoke(sender, e, CallbackHandler, null);

                }


            private void Calculate(object sender, EventArgs e)

                {

                    CalculateDelegate ad = new CalculateDelegate(MyClass.SetCalculate);

                    AsyncCallback CallbackHandler = new AsyncCallback(MyCallbackMethodCalc);

                    ad.BeginInvoke(sender, e, cphPanels, CallbackHandler, null);

                }


            public void MyCallbackMethodVis(IAsyncResult ar)

            {

                AsyncResult result = (AsyncResult)ar;

                AsyncCustomDelegate gsld = (AsyncCustomDelegate)result.AsyncDelegate;

                gsld.EndInvoke(ar);

            }

            public void MyCallbackMethodCalc(IAsyncResult ar)

            {

                AsyncResult result = (AsyncResult)ar;

                result.AsyncDelegate.GetType();

                CalculateDelegate gsld = (CalculateDelegate)result.AsyncDelegate;

                gsld.EndInvoke(ar);

            }


    Thank you in advance for helping.Smile

Page 1 of 1 (1 items)