Hello All
I'm having trouble with a Thread.Sleep issue, as I'm purposley trying to cause a 5 minute delay in a service oriented application I'm supporting. When monitoring for a specific exception, I'm using a Thread.Sleep(300000) statement. 300,000 milliseconds = 5 minutes, right? Trouble is, the delays encountered are never 5 minutes, always less, and they vary, sometimes 30 seconds, sometimes 40 seconds, sometimes a full minute. Anybody have any idea why?
Note: I have my Thread.Sleep(300000) in a catch block where I'm monitoring for IOException, specifically a semaphore timeout period. Would this type of exception cause the thread.sleep to behave sporadically as I described above? The five minute delays seem to work consistently in other areas of the application.
Any insights? Would be appreaciated!
Thanks!
Loading
Sam HobbsPosted Oct 28, 2010, 6:53 PM
Scott LackeyPosted Oct 28, 2010, 3:58 PM
Sam HobbsPosted Oct 28, 2010, 3:41 PM
I certainly recommend using a timer instead of Sleep. The only advntage of Sleep is that it is easy; there is no other advantage. A big disadvantage is that it puts the entire thread asleep, so it will prevent the thread from dong anything else. That could be related to the problem but I am not sure.
Scott LackeyPosted Oct 28, 2010, 11:03 AM
When I do the thread.sleep(300000) in a different error condition, say invalid XML format (just as a test), the five minute delay works fine, leading me to believe the nature of the error being monitored for (IOException) inheritantly causes the problem. I could either use a longer delay period, or try to use a timer function instead of thread.sleep, but I'm thinking that using a timer process for creating for the delay when monitoring for IOException may just have the same problem.
Any ideas? Thanks!
******************
catch (IOException e)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("IO Exception thrown:");
sb.AppendLine("===================================");
sb.AppendLine("Message: ");
sb.AppendLine(e.Message);
sb.AppendLine();
sb.AppendLine("Stack Trace: ");
sb.AppendLine(e.StackTrace);
sb.AppendLine();
sb.AppendLine("Path: ");
sb.AppendLine(SOURCE_FILEPATH);
string[] to = new string[] { "scott.lackey@*********.com" };
Event error = new Event(5, e.Message, e.StackTrace, SERVICE_NAME, errordate);
EventProvider.Add(error);
error_count++;
if (error_count > 3)
{
Utils.SendEmail(to, cc, "scott.lackey@****.com", "APPLICATION ERROR: RunQueuer", sb.ToString(), MailPriority.High);
Utils.StopWithErrorEntry(5, e.Message, e.StackTrace, SERVICE_NAME);
}
Thread.Sleep(300000);
}
************************
JurePosted Oct 28, 2010, 10:27 AM
But it's unlikely that you have a code whose difference of execution time is that big, unless you're testing the code with different data each time...
Can you post that part of the code and any part related?