| Author |  | 
      
        | Blixt Newbie
 
  
 
 Joined: 24 August 2009
 Location: Sweden
 Online Status: Offline
 Posts: 10
 | 
          Hi there,
           | Posted: 26 August 2009 at 6:27am | IP Logged |   |  
           | 
 |  
 I've got an Imap object idling for a longer
 period of time using the BeginIdle method.
 Sometimes, the connection is interrupted,
 causing a
 MailBee.MailBeeAbortedByRemoteHostException
 exception. While I can see the error before it
 occurs using the ErrorOccurred event, I cannot
 handle the exception (i.e., reconnect.) Instead,
 the application crashes. The code that throws
 the exception is in a thread created by the
 MailBee.NET code so I can't catch it.
 
 Should I create my own thread that does idling
 using Idle, or is there a way to handle the
 exception?
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Igor AfterLogic Support
 
  
 
 Joined: 24 June 2008
 Location: United States
 Online Status: Offline
 Posts: 6168
 | 
          The main reason of the issue is that IMAP server will stop idling and will close connection if idling is active for too long time (29 mins is default limit). Thus, we suggest to add a timer-based handler which performs reconnection to IMAP server, say, every 15-20 mins.
           | Posted: 26 August 2009 at 6:39am | IP Logged |   |  
           | 
 |  
 Regarding handling exceptions of asynchronous methods, you'll find an example on this documentation page; the approach assumes using callback function with a try/catch block.
 
 --
 Regards,
 Igor, AfterLogic Support
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Blixt Newbie
 
  
 
 Joined: 24 August 2009
 Location: Sweden
 Online Status: Offline
 Posts: 10
 | 
          Yeah, in this case it was the timeout (after
           | Posted: 26 August 2009 at 6:43am | IP Logged |   |  
           | 
 |  exactly 35 minutes), but I want to make my code
 safe even if the network connection goes down or
 something like that. I will implement a
 reconnection every 20 minutes or so.
 
 Okay, so is it safe to assume that all
 exceptions are thrown in the EndIdle method? So
 no exceptions are thrown in the thread spawned
 by BeginIdle?
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Igor AfterLogic Support
 
  
 
 Joined: 24 June 2008
 Location: United States
 Online Status: Offline
 Posts: 6168
 | 
          Yes, quite right. Note that BeginIdle may still cause exceptions connected to errors in the code, e.g. wrong method parameters or method call when there's no active connection to server.
           | Posted: 26 August 2009 at 6:48am | IP Logged |   |  
           | 
 |  
 --
 Regards,
 Igor, AfterLogic Support
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Blixt Newbie
 
  
 
 Joined: 24 August 2009
 Location: Sweden
 Online Status: Offline
 Posts: 10
 | 
          Okay! Thanks once again for your quick help! =)
           | Posted: 26 August 2009 at 6:58am | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Blixt Newbie
 
  
 
 Joined: 24 August 2009
 Location: Sweden
 Online Status: Offline
 Posts: 10
 | 
          Hi again,
           | Posted: 02 September 2009 at 4:48am | IP Logged |   |  
           | 
 |  
 This code has been running fine for a few days
 since I added periodical reconnection. I also
 added try...catch in the EndIdle to handle
 errors. However, a connection error occurred
 recently that appears to be outside my code:
 
 
 
| Code: 
 
    
    | 
      
       | MailBee.MailBeeSocketObjectDisposedException:
 The socket object used by MailBee was
 unexpectedly closed. InnerException message
 follows: ---> System.IO.IOException  --->
 System.Net.Sockets.SocketException
 
 System.Net.Sockets.NetworkStream.Read(Byte[]
 buffer, Int32 offset, Int32 size)
 
 
 System.Net.Sockets.NetworkStream.Read(Byte[]
 buffer, Int32 offset, Int32 size)
 dr.a(Byte[] A_0, Int32 A_1)
 
 dr.a(Exception A_0)
 dr.a(Byte[] A_0, Int32 A_1)
 c0.ak()
 gx.u()
 cx.e(Boolean A_0)
 
 |  |  |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Igor AfterLogic Support
 
  
 
 Joined: 24 June 2008
 Location: United States
 Online Status: Offline
 Posts: 6168
 | 
          To let us help you on this, please enable logging IMAP session into a file, reproduce the issue and provide us with the log file for examination.
           | Posted: 02 September 2009 at 5:06am | IP Logged |   |  
           | 
 |  
 --
 Regards,
 Igor, AfterLogic Support
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Blixt Newbie
 
  
 
 Joined: 24 August 2009
 Location: Sweden
 Online Status: Offline
 Posts: 10
 | 
          Hello again. I enabled logging and here are the
           | Posted: 06 September 2009 at 11:18pm | IP Logged |   |  
           | 
 |  last few lines before the error:
 
 
| Code: 
 
    
    | 
      
       | [10:48:55.39] [INFO] Will go idle. [10:48:55.39] [SEND] MBN00000006 IDLE\r\n
 [10:48:55.39] [RECV] + IDLE accepted, awaiting
 DONE command.\r\n [Total 41 bytes received.]
 [11:08:55.32] [INFO] Will finish idling.
 [11:08:55.32] [SEND] DONE\r\n
 [11:09:14.28] [INFO] Error: The socket object
 used by MailBee was unexpectedly closed.
 InnerException message follows: Det gick inte
 att läsa data från transportanslutningen:
 Anslutningsförsöket misslyckades eftersom den
 anslutna datorn inte svarade inom en viss tid
 eller på grund av att den etablerade
 anslutningen till värddatorn inte längre
 fungerar.
 [11:09:14.32] [INFO] Will disconnect from host
 "172.31.152.80".
 [11:09:14.32] [INFO] Disconnected from host
 "172.31.152.80".
 |  |  |  
 The server is running in Swedish so the
 exception is localized, but I'll try to
 translate it: "Could not read data from the
 transport connection: The connection attempt
 failed due to the connected computer not
 responding within a certain period of time or
 because the established connection to the host
 is no longer working."
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          The world is unfair. Although IMAP RFC claims the server must support 30 minutes of idling, many servers ignore this and close the connection after just a few minutes. Your case, it seems. Try to lower the reconnection interval to 3 minutes.
           | Posted: 07 September 2009 at 5:20am | IP Logged |   |  
           | 
 |  
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Blixt Newbie
 
  
 
 Joined: 24 August 2009
 Location: Sweden
 Online Status: Offline
 Posts: 10
 | 
          Hello Alex,
           | Posted: 07 September 2009 at 5:44am | IP Logged |   |  
           | 
 |  
 The service usually works fine for a few days,
 then a hiccup occurs which throws an exception
 that I cannot catch. So it doesn't matter if I
 reconnect every minute, the connection can
 still break unexpectedly and in such a case I
 have to handle the exception.
 
 If this isn't possible I'll have to put the
 connection handler on its own thread and
 forcefully restart it as well to prevent the
 main thread from crashing. But it would be
 more convenient to be able to catch the
 exception, since it's obviously caught by your
 library before being passed on (but not to my
 code, it seems?)
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          This topic discusses handling exceptions in worker threads: Not receiving idle notifications
           | Posted: 07 September 2009 at 6:10am | IP Logged |   |  
           | 
 |  
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | setven17 Newbie
 
  
 
 Joined: 04 October 2009
 Location: Philippines
 Online Status: Offline
 Posts: 2
 | 
          whoa! at last I've come up on the solution. thanks even confusion took place before on the codes but it's okay now.
           | Posted: 05 October 2009 at 1:41am | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | tromby24 Newbie
 
  
 
 Joined: 23 October 2009
 Location: Philippines
 Online Status: Offline
 Posts: 2
 | 
          
           | Posted: 24 October 2009 at 2:12am | IP Logged |   |  
           | 
 |  Tengo un servidor IMAP objeto ralentí durante un largo
 período de tiempo utilizando el método de BeginIdle.
 A veces, se interrumpe la conexión,
 causando una
 MailBee.MailBeeAbortedByRemoteHostException
 excepción. Aunque puedo ver el error antes de que
 se produce utilizando el evento ErrorOccurred, no puedo
 controlar la excepción (es decir, volver a conectar.) Por el contrario,
 la aplicación se bloquea. El código que arroja
 La excepción es en un hilo creado por el
 Código MailBee.NET así que no puedo cogerlo.
 
 ¿Debo crear mi propio hilo que hace al ralentí
 utilizando inactivo, o hay una manera de manejar la
 excepción?
 | 
       
        | Back to Top |     | 
       
       
        |  |