Ejemplo n.º 1
0
 public void UseDelegateCallback()
 {
     //This method uses the registered client ref to call back
     //into the client
     //Make sure something is registered first
     if (del1 != null)
     {
         //Call back into the client code
         del1.BeginInvoke(null, null);
     }
 }
Ejemplo n.º 2
0
    private void cmdBuiltInCallback_Click(object sender, System.EventArgs e)
    {
        //Delegates have a built-in mechanism to call back into the client. The
        //method to be called back into must have a specific signature, however.
        //This method will use the built-in callback of an asynchronous invocation
        //on a delegate, and will call into the BuiltInCallback method below this one.
        //Note that no user registration is needed.
        Class1 refClass1 = new Class1();

        //Create an instance of a delegate to represent the callback method
        Delegate1 d = new Delegate1(refClass1.UseBuiltInDelegateCallback);

        //Now create a second delegate to pass to the callee. The callee will use
        //This second delegate to call back into the client. AsyncCallback is
        //defined in the CLR specifically for calling back after an asynchronous
        //invocation of a delegate.
        AsyncCallback ac = new AsyncCallback(this.BuiltInCallback);

        //Invoke the class one method. Note that this invocation is asynchronous,
        //and will be carried out on a worker thread from the CLR thread pool. The
        //resulting callback will also be performed by the worker thread. The
        //callback delegate is passed in as an argument, so no explicit registration
        //is needed.
        d.BeginInvoke(ac, null);
    }
Ejemplo n.º 3
0
        public void buttonFind2_Click(object sender, EventArgs e)
        {
            Delegate1 d1 = new Delegate1(Find);

            d1.BeginInvoke(new AsyncCallback(AsyncCallback1), d1);
        }