} // Run() // Call back method to capture results private void ResultsReturned(IAsyncResult iar) { DelegateThatReturnsInt ThisDelegate; int result; // Cast the state object back to the delegate type ThisDelegate = ( DelegateThatReturnsInt )iar.AsyncState; // Call EndInvoke on the delegate to get the results result = ThisDelegate.EndInvoke(iar); // Display the results Console.WriteLine("Delegate returned result: {0}", result); } // ResultsReturned()
public void Run() { for ( ; ;) { // Sleep for a half second Thread.Sleep(500); if (theDelegate != null) { // Explicitly invoke each delegated method foreach (DelegateThatReturnsInt ThisDelegate in theDelegate.GetInvocationList()) { // Invoke asynchronously // Pass the delegate in as a state object ThisDelegate.BeginInvoke(new AsyncCallback(ResultsReturned), ThisDelegate); } } } } // Run()