Question

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

Was it helpful?

Solution

Thread.Sleep(int) is what I would use.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top