private void button1_Click(object sender, EventArgs e) { AsyncResult asyncResult = m_Result as AsyncResult; MyFunctionDelegate d = asyncResult.AsyncDelegate as MyFunctionDelegate; d.EndInvoke(m_Result); this.CloseForm(); }
public MyClass() : base() { // instantiate the delegate (AKA create the pointer) MyFunctionDelegate myFunctionDelegate = new MyFunctionDelegate(); // map a valid handler (with the same signature) to this delegate // I'm using "+=" operator because you can add more than one handler to a collection myFunctionDelegate += new MyFunctionDelegate(PrintValues); // invoke the handler method (which in this case is PrintValues() - see below) myFunctionDelegate(1, "Test"); }
public MyClass() : base() { // instantiate the delegate (AKA create the pointer) MyFunctionDelegate myFunctionDelegate = new MyFunctionDelegate(); // map a valid method handler (WITH THE SAME SIGNATURE) to this delegate // I'm using "+=" operator because you can add more than one handler to a collection myFunctionDelegate += new MyFunctionDelegate(PrintValues); // invoke the method handler (which in this case is PrintValues() - see below) // NOTE THE SIGNATURE OF THIS CALL myFunctionDelegate(1, "Test"); }
private void Completed(IAsyncResult result) { System.Runtime.Remoting.Messaging.AsyncResult asyncResult = result as System.Runtime.Remoting.Messaging.AsyncResult; MyFunctionDelegate myDelegate = (MyFunctionDelegate)asyncResult.AsyncDelegate; DialogResult dialogResult = myDelegate.EndInvoke(asyncResult); if (dialogResult == DialogResult.OK) { MessageBox.Show("OK!"); } else { MessageBox.Show("Cancelled!"); } }
private void button1_Click(object sender, EventArgs e) { Person p = new Person(); p.Name = "Wilson"; p.Age = 22; frm = null; MyFunctionDelegate myDelegate = new MyFunctionDelegate(MyFunction); IAsyncResult result = myDelegate.BeginInvoke(p, new AsyncCallback(Completed), null); frm = new FrmWait(result, myDelegate); frm.ShowDialog(); //if (frm.ShowDialog() == DialogResult.OK) //{ // MessageBox.Show("OK!"); //} //else //{ // MessageBox.Show("Cancelled!"); //} }
public void SomeFunction(MyFunctionDelegate myFunction) { myFunction(_some, _args); }
public FrmWait(IAsyncResult result, MyFunctionDelegate d) { InitializeComponent(); m_Result = result; m_Delegate = d; }
public static extern void follower(int q, MyFunctionDelegate fn);