Cette situation est difficile à expliquer. Avoir un processus de service qui démarre 2 threads, chaque thread boucle pour toujours mais dort pendant 5 minutes chacun une fois que la charge est terminée.Le processus est terminé en raison de StackOverflowException
Problème est que mon deuxième thread se termine bien avant que la charge est même terminée, sans raison apparente, et je ne peux pas non plus attraper l'exception car elle semble être déclenchée en dehors du processus de délégation?
Des suggestions sur comment trouver le problème?
Le code ....
public void StartService()
{
ThreadStart stRecieve = new ThreadStart(DownloadNewMail);
ThreadStart stSend = new ThreadStart(SendNewMail);
senderThread = new Thread(stRecieve);
recieverThread = new Thread(stSend);
sendStarted = true;
recieveStarted = true;
senderThread.Start();
recieverThread.Start();
}
private void DownloadNewMail()
{
while(recieveStarted)
{
//Payload....
if (recieveStarted)
{
Thread.Sleep(new TimeSpan(0, confSettings.PollInterval, 0));
}
}
}
private void SendNewMail()
{
while(sendStarted)
{
//Payload....
if (sendStarted)
{
Thread.Sleep(new TimeSpan(0, confSettings.PollInterval, 0));
}
}
}
Une erreur 'StackOverflowException' est souvent provoquée par des récursions trop profondes ou par des instanciations circulaires. Utilisez-vous la récursivité n'importe où? – LukeH
"chaque thread boucle pour toujours" <- publiez ce code ici –
J'ai réussi à le résoudre en créant les threads comme statiques ... –