Pourquoi mon Thread.Interrupt ne fonctionne pas?Thread.Interrupt ne fonctionne pas
Le code faisant l'interruption:
public void Stop()
{
const string LOG_SOURCE = "ProcessingDriver";
if (_Enabled)
{
try
{
RequestProcessor.Disable();
if (ProcessingThread != null)
{
ProcessingThread.Interrupt();
ProcessingThread.Join();
}
}
catch (Exception ex)
{
WriteLog(LOG_SOURCE, ex);
}
}
}
Le code que je pense à arrêter:
private void ProcessRequests()
{
const string LOG_SOURCE = "ProcessRequests";
try
{
ProcessingThread = Thread.CurrentThread;
while (!_Disposed)
{
_ProcessingWaitHandle.WaitOne();
int count = GetRequestCount();
while (count > 0)
{
try
{
ExportRequest er = GetRequest();
ProcessRequest(er);
}
catch (ThreadInterruptedException)
{
throw;
}
catch (Exception ex)
{
WriteLog(LOG_SOURCE,
ex);
WriteLog(LOG_SOURCE,
"Request Failed.");
}
//Suspend to catch interupt
Thread.Sleep(1);
count = GetRequestCount();
}
}
}
catch (ThreadInterruptedException)
{
WriteLog(LOG_SOURCE,
"Interupted. Exiting.", LogType.Info);
}
catch (Exception critEx)
{
//Should never get here
WriteLog(LOG_SOURCE, critEx);
WriteLog(LOG_SOURCE,
"Serious unhandled error. Please restart.", LogType.Critical);
}
}
J'étagé dans le code. Je peux voir Interruption étant appelée (Veille ou attendre ne sont pas les commandes actives à ce moment), et je peux voir le sommeil être appelé, mais aucune erreur d'interruption n'est jamais levée (ni sur le sommeil, ni sur le WaitOne, même quand le fil blocs sur WaitOne).
Qu'est-ce que je fais mal?
Note: .Net 2.0
+1 pour la clarté et la divulgation. –