I need a slow C# function

前端 未结 6 2046
耶瑟儿~
耶瑟儿~ 2020-12-05 09:47

For some testing I\'m doing I need a C# function that takes around 10 seconds to execute. It will be called from an ASPX page, but I need the function to eat up CPU time on

6条回答
  •  一向
    一向 (楼主)
    2020-12-05 10:37

    Arguably the simplest such function is this:

    public void Slow()
    {
        var end = DateTime.Now + TimeSpan.FromSeconds(10);
        while (DateTime.Now < end)
               /* nothing here */ ;
    }
    

提交回复
热议问题