Tag: wait

kernel32.dll Sleep和Thread.Sleep()之间的任何区别

以下内容之间是否存在任何差异(性能,实施……无论如何): 一世) DllImport(“kernel32.dll”)] public extern static void Sleep(uint msec); ..然后调用睡眠function II) Thread.Sleep()

如何并行运行任务并选择满足C#中给定条件的第一个结果?

我希望并行运行三个任务。 我希望检查完成的第一个任务的结果,并检查以确定结果是否良好 。 如果是,我取消所有其他任务并返回此结果,如果没有,我将等待下一个完成的任务并检查是否良好 ,如果是,则执行相同操作。 (想想在OutputDataType的成员上做一些简单的检查)。 我继续这个,直到我获得一个结果良好的完成任务,或者所有任务返回的结果都不好 ,在这种情况下我返回null 。 先感谢您。 using System; using System.Threading; using System.Threading.Tasks; namespace myNamespace { class Program { static void Main() { InputDataType data = getMyData(); OutputDataType x = Foo(data); } static OutputDataType Foo(InputDataType data) { Task task1 = null, task2 = null, taks3 = null; Task[] TaskArray = { task1, […]

我如何等到任务在C#中完成?

我想向服务器发送请求并处理返回的值: private static string Send(int id) { Task responseTask = client.GetAsync(“aaaaa”); string result = string.Empty; responseTask.ContinueWith(x => result = Print(x)); responseTask.Wait(); // it doesn’t wait for the completion of the response task return result; } private static string Print(Task httpTask) { Task task = httpTask.Result.Content.ReadAsStringAsync(); string result = string.Empty; task.ContinueWith(t => { Console.WriteLine(“Result: ” + […]

如何使脚本以统一的简单方式等待/睡眠

如何在TextUI.text = ….之间TextUI.text = ….一个sleep函数,在每个短语之间等待3秒? public Text GuessUI; public Text TextUI; […truncated…] TextUI.text = “Welcome to Number Wizard!”; TextUI.text = (“The highest number you can pick is ” + max); TextUI.text = (“The lowest number you can pick is ” + min); 我已经尝试了各种各样的东西,但没有奏效,这样: TextUI.text = “Welcome to Number Wizard!”; yield WaitForSeconds (3); TextUI.text = (“The […]