Tôi nghe nói rằng có bốn mẫu trong thực thi không đồng bộ.C# -Các mẫu trong thực thi không đồng bộ
"Có bốn mẫu trong thực hiện đại diện async: Polling, chờ hoàn thành, thông báo hoàn thành, và " Fire và Forget"
Khi tôi có đoạn mã sau:
class AsynchronousDemo
{
public static int numberofFeets = 0;
public delegate long StatisticalData();
static void Main()
{
StatisticalData data = ClimbSmallHill;
IAsyncResult ar = data.BeginInvoke(null, null);
while (!ar.IsCompleted)
{
Console.WriteLine("...Climbing yet to be completed.....");
Thread.Sleep(200);
}
Console.WriteLine("..Climbing is completed...");
Console.WriteLine("... Time Taken for climbing ....{0}",
data.EndInvoke(ar).ToString()+"..Seconds");
Console.ReadKey(true);
}
static long ClimbSmallHill()
{
var sw = Stopwatch.StartNew();
while (numberofFeets <= 10000)
{
numberofFeets = numberofFeets + 100;
Thread.Sleep(10);
}
sw.Stop();
return sw.ElapsedMilliseconds;
}
}
1) Mẫu mã trên được triển khai như thế nào?
2) Bạn có thể giải thích mã không, làm cách nào tôi có thể thực hiện phần còn lại ..?
Tôi ước gì mình có Stack Overflow để làm bài tập về nhà Khoa học Máy tính của mình cho tôi khi tôi ở Đại học ...:) –