コード例 #1
0
//        private void CalcCallback(IAsyncResult ar)
//{
//    // Following line is used when this callback method can not acquire a handle of the delegate, mDeleg, for
//    // example, when it is in another class. The AsyncDelegate property was generated by the compiler together
//    // with the BeginInvoke and EndInvoke methods.
//    // CalcDelegate mDeleg = (CalcDelegate)(ar.AsyncDelegate);

//    string strResult = null;

//    int iResult = mDeleg.EndInvoke(ref strResult, ar);

//    tbResult.Text = Convert.ToString(iResult); // the third textbox
//    tbMsg.Text = strResult; // the message textbox
//    int i = (int)ar.AsyncState;
//    MessageBox.Show("The ar.AsyncState is " + i); // will show 123456789
//   }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //mDeleg = new CalcDelegate(Calc);
            //AsyncCallback callback = new AsyncCallback(CalcCallback);

            //int input1 = Convert.ToInt16(tbInput1.Text);
            //int input2 = Convert.ToInt16(tbInput2.Text);
            //string strResult = null; // dummy parameter

            //mDeleg.BeginInvoke(input1, input2, ref strResult, callback, 123456789);


            CalcDelegate deleg = new CalcDelegate(Calc);
            //AsyncCallback callback = new AsyncCallback(CalcCallback);
            int          input1    = Convert.ToInt16(tbInput1.Text);
            int          input2    = Convert.ToInt16(tbInput2.Text);
            string       strResult = null; // dummy parameter
            IAsyncResult ar        = deleg.BeginInvoke(input1, input2, ref strResult, null, new object());

            //deleg.BeginInvoke(input1, input2, ref strResult, callback, new object());
            ar.AsyncWaitHandle.WaitOne();

            strResult = null;
            int iResult = deleg.EndInvoke(ref strResult, ar);

            tbResult.Text = Convert.ToString(iResult);
            tbMsg.Text    = strResult;
        }
コード例 #2
0
ファイル: MainWindow.cs プロジェクト: tigros/GMPCalcGTK
    protected void apress(object sender, EventArgs e)
    {
        if (!validinput())
        {
            return;
        }

        if (button4.Label == "Cancel")
        {
            button4.Label     = "Pending";
            Globals.cancelled = true;
            return;
        }
        else if (button4.Label == "Pending")
        {
            button4.Label     = "Cancel";
            Globals.cancelled = false;
            return;
        }

        GLib.Timeout.Add(100, new GLib.TimeoutHandler(timerTick));

        CalcDelegate cd = RunCalc;

        button4.Label = "Cancel";

        starttime = DateTime.Now;

        IAsyncResult asyncRes = cd.BeginInvoke(textview1.Buffer.Text, xtext.Buffer.Text, ytext.Buffer.Text, ztext.Buffer.Text,
                                               calcprec.Buffer.Text, printprec.Buffer.Text, digitgrp.Active, new AsyncCallback(CalcCallback), null);
    }