This article describes the usage of asynchronous callback functions in C#. Share it for your reference. The details are as follows:
static void Main(string[] args) { Func<string,string> showMessage = ShowMessage; //The callback function Completed is set, and there is no return value IAsyncResult result = ("Test asynchronous delegation",new AsyncCallback(Completed),null); //Whether the half-segment asynchronous ends while(!) { ("The main thread can perform other operations!"); } (); } static string ShowMessage(string x) { string current = ("Current threadidfor{0}",); (3000); return ("{0},输入for{1}", current, x); } static void Completed(IAsyncResult result) { ("Asynchronous completion!"); //Get the delegate object and use the EndInvoke method to get the return result AsyncResult _result = (AsyncResult) result; Func<string, string> showMessage = (Func<string, string>) _result.AsyncDelegate; //End asynchronous operation and output ((_result)); }
I hope this article will be helpful to everyone's C# programming.