如果你能让我知道多次异步调用相同的方法,我将不胜感激.我更感兴趣的是了解这项活动的安全性.我在这里发布了一个控制台代码,其中包含一个我异步调用四次的方法,它运行良好.到目前为止,我没有注意到任何打嗝.但我想确定.请使用以下代码:
public class OneMethodCalledServeralTimes
{
protected async Task<bool> DoSomeWork(Values values, int whenItIsCalled, string description)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
await Task.Delay(values.Value);
Console.WriteLine("{0} Completed in {1} and this was called: {2}",description, stopWatch.ElapsedMilliseconds, whenItIsCalled);
return true;
}
public bool DoAllWork()
{
Console.WriteLine("=====================Started doing weekend Chores===================");
var task1 = DoSomeWork(new Values { Value = 10000 }, 1, "First work to be done");
var task2 = DoSomeWork(new Values {Value = 7000}, 1, "First work to be done");
var task3 = DoSomeWork(new Values …Run Code Online (Sandbox Code Playgroud)