I need a slow C# function

前端 未结 6 2052
耶瑟儿~
耶瑟儿~ 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:31

    This is CPU intensive on a single thread/CPU, and lasts 10 seconds.

    var endTime = DateTime.Now.AddSeconds(10);
    
    while(true) {
       if (DateTime.Now >= endTime) 
          break;
    }
    

    As a side note, you should not normally do this.

提交回复
热议问题