Monday, April 05, 2010

Simple C# Wait Statement

I'm in a scenario where I'm making a get call to a web service, and if the get call fails for some reason I have to immediately call the web service back and let the client's know there is something up with their data. Well, apparently closing your web connection and then immediately calling it sometimes creates issues, as even though the service is closed, there is a little latency. So I was doing a thread.sleep before calling back, and that caused some issues. So here is a little wait statement equivalent I found

DateTime waitTime = DateTime.Now + TimeSpan.FromSeconds(2);
while (waitTime < DateTime.Now) {;}

Simple. Found it here - http://forums.xna.com/forums/p/908/6180.aspx

No comments: