| Author | 
         | 
         
      
        
         
         Blixt Newbie 
          
 
  Joined: 24 August 2009 Location: Sweden
 Online Status: Offline Posts: 10
          | 
        
         
          
           | Posted: 24 August 2009 at 7:43am | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Hi there, I have the following initialization 
 code:
 
 Imap.LicenseKey = 
 Settings.Default.MailBeeLicenseKey;
 
 ImapObject = new Imap();
 ImapObject.MessageStatus += new 
 ImapMessageStatusEventHandler(MessageStatusUpd
 ated);
 ImapObject.SslMode = 
 Settings.Default.ImapSslMode;
 ImapObject.Connect(Settings.Default.ImapHost, 
 Settings.Default.ImapPort);
 ImapObject.Login(Settings.Default.ImapUser, 
 Settings.Default.ImapPassword);
 ImapObject.ExamineFolder("Inbox");
 
 When I run it, I get the exception "There is 
 already an operation in progress." on the 
 ExamineFolder line. The account being 
 connected to is a Gmail account. The error 
 worked at first but appeared after a code 
 refactoring, but the strange thing is that no 
 mail-related code was changed.
 
 Does anyone know any reasons this error could 
 appear?
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         Igor AfterLogic Support 
          
 
  Joined: 24 June 2008 Location: United States
 Online Status: Offline Posts: 6168
          | 
        
         
          
           | Posted: 24 August 2009 at 7:54am | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Most probably, this has something to do with ImapMessageStatusEventHandler usage, looks like some IMAP server access operation is performed there at the moment when ExamineFolder command is executed. Try to remove that line of code temporarily and check if the issue persists.
 
 --
 Regards,
 Igor, AfterLogic Support
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         Blixt Newbie 
          
 
  Joined: 24 August 2009 Location: Sweden
 Online Status: Offline Posts: 10
          | 
        
         
          
           | Posted: 25 August 2009 at 12:34am | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Removing the ExamineFolder/SelectFolder call 
 (I tried both) stops the error from occurring 
 (well, I get an error on Idle telling me that 
 I have to select a folder, but this is 
 expected.)
 
 Any ideas why the ExamineFolder/SelectFolder 
 calls are causing this error? Here's the 
 output of the exception:
 
 MailBee.MailBeeExternalException 
 was unhandled
   Message="User code has thrown an exception. 
 InnerException message follows: There is 
 already an operation in progress."
   Source="MailBee.NET"
   ErrorCode=7
   StackTrace:
        vid gk.a(Delegate A_0, Object[] A_1)
        vid gx.a(String A_0, Int32 A_1, 
 MessageFlagSet A_2)
        vid gx.b(Boolean A_0)
        vid gx.ae()
        vid bb.b(String A_0, e5 A_1, Boolean 
 A_2)
        vid bb.a(String A_0, e5 A_1, Boolean 
 A_2)
        vid gx.a(String A_0, Boolean A_1)
        vid gx.d(String A_0, Boolean A_1)
        vid cx.c(String A_0, Boolean A_1)
        vid cx.c(Boolean A_0, String A_1, 
 Boolean A_2)
        vid 
 MailBee.ImapMail.Imap.ExamineFolder(String 
 folderName)
        vid 
 Skanemejerier.SkanemejerierService.Connect() i 
 C:\Documents and Settings\Administratör\Mina 
 dokument\Visual Studio 
 2008\Projects\MMSImport\SkanemejerierShakeServ
 ice\SkanemejerierService.cs:rad 105
        vid ServiceTester.Program.Main(String[] 
 args) i C:\Documents and 
 Settings\Administratör\Mina dokument\Visual 
 Studio 
 2008\Projects\MMSImport\ServiceTester\Program.
 cs:rad 15
        vid 
 System.AppDomain._nExecuteAssembly(Assembly 
 assembly, String[] args)
        vid 
 System.AppDomain.ExecuteAssembly(String 
 assemblyFile, Evidence assemblySecurity, 
 String[] args)
        vid 
 Microsoft.VisualStudio.HostingProcess.HostProc
 .RunUsersAssembly()
        vid 
 System.Threading.ThreadHelper.ThreadStart_Cont
 ext(Object state)
        vid 
 System.Threading.ExecutionContext.Run(Executio
 nContext executionContext, ContextCallback 
 callback, Object state)
        vid 
 System.Threading.ThreadHelper.ThreadStart()
   InnerException: 
 MailBee.MailBeeInvalidStateException
        Message="There is already an operation 
 in progress."
         Source="MailBee.NE T"
        ErrorCode=3
        StackTrace:
               vid gk.i(Boolean A_0)
               vid cx.a(Boolean A_0, Boolean A_1, 
 String A_2, String A_3, String A_4)
               vid 
 MailBee.ImapMail.Imap.Search(Boolean 
 returnUids, String searchCondition, String 
 charset)
               vid 
 Skanemejerier.SkanemejerierService.MessageStat
 usUpdated(Object sender, 
 ImapMessageStatusEventArgs e) i C:\Documents 
 and Settings\Administratör\Mina 
 dokument\Visual Studio 
 2008\Projects\MMSImport\SkanemejerierShakeServ
 ice\SkanemejerierService.cs:rad 46
        InnerException: 
 
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         Igor AfterLogic Support 
          
 
  Joined: 24 June 2008 Location: United States
 Online Status: Offline Posts: 6168
          | 
        
         
          
           | Posted: 25 August 2009 at 12:49am | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Actually, I meant removing the following line:
 
Code: 
   
    
    
      
       | ImapObject.MessageStatus += new ImapMessageStatusEventHandler(MessageStatusUpdated); | 
       
       | 
    
    | 
 
 
 
 The issue seems to be caused by the code used in MessageStatusUpdated method; make sure this method does not contain any requests to IMAP server. As the method is asynchronous, it can work at the same time when main code is executed.
 
 --
 Regards,
 Igor, AfterLogic Support
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         Blixt Newbie 
          
 
  Joined: 24 August 2009 Location: Sweden
 Online Status: Offline Posts: 10
          | 
        
         
          
           | Posted: 25 August 2009 at 12:57am | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Oooh, I see. Yeah, that is probably the cause! 
 There is some code that fetches e-mails in the 
 inbox in the callback.
 
 The purpose of the code is to wait for incoming 
 e-mails and handle them as they arrive. Should I 
 instead set a flag in the MessageStatusUpdated 
 method and fetch the e-mails in the Idling 
 event, or is there any other recommended way of 
 doing this?
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         Igor AfterLogic Support 
          
 
  Joined: 24 June 2008 Location: United States
 Online Status: Offline Posts: 6168
          | 
        
         
          
           | Posted: 25 August 2009 at 1:08am | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
We have a sample code for using IMAP IDLE, you can download it at:
 
 IDLE Sample
 
 Hope this helps.
 
 --
 Regards,
 Igor, AfterLogic Support
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         Blixt Newbie 
          
 
  Joined: 24 August 2009 Location: Sweden
 Online Status: Offline Posts: 10
          | 
        
         
          
           | Posted: 25 August 2009 at 2:44am | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
I've got it working now! Thanks for your help!
 
 Regards,
 Andreas
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   |