BeginInvoke的用法

using System;
using System.Threading;
class MyTest
{
	delegate bool deleTest(string a,string b);
	static void Main(string[] args)
	{
		deleTest mytest = new deleTest(Test);
		IAsyncResult testRecult = mytest.BeginInvoke("a", "b", null, null);

		Write();
		
		Console.WriteLine(mytest.EndInvoke(testRecult));
	}
	public static bool Test(string s1, string s2)
	{
		Thread.Sleep(3000);
		Console.WriteLine("InTest");
		if (s1 == s2)
			return true;
		return false;
	}

	public static void Write()
	{
		Console.WriteLine("InWrite");
	}
}
/*
运行结果:

InWrite
InTest
False
*/

你可能感兴趣的:(BeginInvoke的用法)