C#异步回调函数的使用

 

namespace ConsoleApp1
{
    class Program
    {
        static string str = "null";
        static void Main(string[] args)
        {
            test();
        }
        public static void test()
        {
            TestThreadStart(test222);
        }
        public delegate void WeatherSearchCallBack();//回调委托
        public WeatherSearchCallBack weatherSearchCallBack;//回调委托

        public static void TestThreadStart(WeatherSearchCallBack wCallBack)
        {
            Thread td = new Thread(SearchWeather);
            td.Start(wCallBack);
        }
        private static void SearchWeather(object obj)
        {
           str = "SearchWeather";
           WeatherSearchCallBack wCallBack = obj as WeatherSearchCallBack;
           wCallBack();//执行完成后 调用回调函数通知此线程已经执行完成
        }

        static void test222()
        {
            Console.WriteLine("执行回调:"+ str);
        }
    }
}

 

你可能感兴趣的:(应用开发,程序)