Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am unsure why this code stops after running fine for hours. I have a hunch that it has to do with threads being aborted automatically, garbage collection? The project is a winforms project.
Any help would be greatly appreciated!

And here is the code:
C#
public void InstantiateListenerAndResponder()
       {

           try
           {
               var t = new Thread(Listen) { Priority = ThreadPriority.Lowest, IsBackground = true};
               var t2 = new Thread(StartResponder) { Priority = ThreadPriority.Lowest, IsBackground = true};
               ThreadManager.AddThread(this);
               ThreadRunning = true;

               t.Start();
               t2.Start();
           }
           catch (Exception ex)
           {
                var se = new SystemEmailer();
               se.SendMessage("ERROR CODE 104 - \n" + ex.Message);

           }
       }


       private void Listen()
       {

           try
           {
               while (ThreadRunning)
               {
                   try
                   {
                       GetMail(ReceiverEntity.UserName, ReceiverEntity.Password, ReceiverEntity.IncomingUrl, ReceiverEntity.IncomingPort, ReceiverEntity.SecurityType == "SSL", ReceiverEntity.ReceiverId);
                       var se = new SystemEmailer();
                       se.SendMessage("ASR CHECKED EMAIL AT: " + DateTime.Now.ToString());
                       Thread.Sleep(30000);
                   }
                   catch
                   {
                       var se = new SystemEmailer();
                       se.SendMessage("Error checking email. Will try again." + DateTime.Now.ToString());
                   }

               }
           }
           catch (Exception ex)
           {

              var se = new SystemEmailer();
               se.SendMessage("ERROR CODE 103 - \n" + ex.Message);
           }
       }

       private void StartResponder()
       {
           try
           {
               while (ThreadRunning)
               {
                   ExecuteResponder();
                   Thread.Sleep(ReceiverEntity.ResponseInterval * 1000);
               }
           }
           catch (Exception ex)
           {
               var se = new SystemEmailer();
               se.SendMessage("ERROR CODE 102 - \n" + ex.Message);

           }

       }
Posted
Comments
ZurdoDev 3-Jun-14 16:24pm    
Check event viewer for errors or your own logging.
Jay stratemeyer 3-Jun-14 16:30pm    
Thanks, I found the issue in the event log. Hasty question, thanks!
ZurdoDev 3-Jun-14 16:35pm    
Glad to hear it.

1 solution

It was in the event log, thanks RyanDev. Email server was timing out and my try catch was not handling the exception properly. Issue resolved.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Jun-14 18:11pm    
This is not an answer. Such posts are considered as abuse. Please move it the the comment to the post by RyanDev (who cannot get a notification of your post anyway, but will get it if you add a comment).
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900