简体   繁体   中英

Is it sane to use Thread.Sleep(int) in ASP.NET or should I use another method?

I want to introduce a slight wait during some testing functions, to simulate a server call. Is it sane to use Thread.Sleep(int) to introduce the wait or is there a better method to have the server wait?

Note, I'll be pausing long enough for me to visually see a sufficient lag, even tho I don't expect to see such a delay in the actual app. This is for me to visualize the actual delay that could occur.

I plan on running this both in the VS2010 local debugger webserver and in IIS 7. I'm on .NET 3.5

Thread.Sleep(int)就是我要用的。

If you're using MVC and SessionState your requests will be automatially serialized - so if you're checking for race conditions with a random Thread.Sleep() value then Request B will never complete before Request A even if the time slept if less.

ASP.NET MVC and Ajax, concurrent requests?

This is perfectly fine for your test sceanrio. As long as you are not doing stress/load testing or calls to services are synchronous replacing them with simple Sleep gives close approximation of server behavior.

If your code uses asynchronous service calls you may want to emulate slightly more of the service calls and put Sleeps on separate threads as if you call service, but it took long time. This way ASP.Net will behave normally and you may even try some load testing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM