0

I want to build a WebAPI that simply wait for 10 seconds. So I use ASP.NET Core Web Application (.Net Core) template, and changed ValuesController.cs to wait for 10 seconds.

public IEnumerable<string> Get()
{
    System.Threading.Thread.Sleep(10000);//add this row
    return new string[] { "value1", "value2" };
}

But, this WebAPI has a problem. When some clients access WebAPI at the same time, second or later client must wait for more than 10 seconds. Please tell me how to process two or more sessions.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

0

Use await Task.Delay is the newer and preferred pattern instead of Thread.Sleep

alltej
  • 6,787
  • 10
  • 46
  • 87