CallBacks

CallBacks Using Delegate performs action using a delegate, and also requires registration and unregistration for the call.


private void cmdDelegateCallback_Click(object sender, System.EventArgs e)
{
//This method calls into a method of a Class1 instance, which in turn
//calls back into the client via a delegate.
Class1 refClass1 = new Class1();

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

//Register the client, passing a reference to the delegate instance
refClass1.RegisterDelegateForCallback(d);

//Call the method which will in turn call back into the client
refClass1.UseDelegateCallback();

//Unregister the client
refClass1.UnRegisterDelegateForCallback();
}



Class file includes

delegate void Delegate1();
public void RegisterDelegateForCallback(Delegate1 d)
{
del1 = d;
}

public void UnRegisterDelegateForCallback()
{
del1 = null;
}

public void UseDelegateCallback()
{
if (del1 != null)
{
del1.BeginInvoke(null, null);
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: