5

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

4

3 に答える 3

6

Thread.Sleep(int)私が使用するものです。

于 2011-03-16T21:53:29.777 に答える
2

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?

于 2013-02-18T09:29:52.843 に答える
1

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.

于 2011-03-16T22:10:45.213 に答える