Scott Lackey

Scott Lackey

  • NA
  • 9
  • 8.4k

Thread.sleep issue redux

Oct 28 2010 3:35 PM

Seems my eariler post got removed for some reason, so I'll try again
**************************************************************
****************************************************************
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!
I've attached the relevant code.  It basically monitors for IOException, writes the error message out, checks the error count, then eventually puts the thread to sleep for five minutes, then retries the process.  (my service oriented application works by continually monitoring and processing XML input files).  After the third retry, send out notification email and shut down the process.
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);

               }
************************

Answers (1)