none
Event Outlook ItemAdd and freeze RRS feed

  • Question

  • Hi, I'm writing a little vb.net application that manage incoming email from outlook COM.
    When i only handle the ItemAdd, there is no problem, but when i try to rescan the folder from within the function handler, my application freeze.
    Here the code

    Private Sub oNewMail_ItemAdd(ByVal Item As Outlook.MailItem) Handles oNewMail.ItemAdd
       processIncomingEmail(Item)
       checkMailFolder()
    End Sub
    
    Private Sub checkMailFolder()
       Dim items As Outlook.Items 
       Dim item As Outlook.MailItem
      items = Me.objOL.Session.Folders(Me.sFolder).Folders(Me.sNomeCartella).Items 
      'other code
    End Sub
    

    The problem is when i try to set the "items" object.
    I'm using Outlook with an MS Exchange account and i have the Outlook application opened in parallel to this program.

    Thanks in advance

    Friday, April 15, 2011 4:24 PM

Answers

All replies

  • Hi Silver_Shadow,

     

    Thanks for posting in the MSDN Forum.

     

    Would you clarify some questions:

     

    1.      What’s the type of variable “sFolder”? As usual, we use a string or a Integer as an index of the Items collection.

    2.      The same question of “sNomeCartella”.

    3.       Does this snippet come from a VB.NET window forms application?

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 18, 2011 6:00 AM
    Moderator
  • Hi  Tom,

    thanks for the reply!

    The two variabiles (sFolder and sNomeCartella) are two strings that contain the folder name.
    This code is from a Console Application, i hope that this information are useful!

     

    Thanks,

    Silver Shadow

    Monday, April 18, 2011 10:53 AM
  • Hi Silver_Shadow,

     

    I can reproduce your issue on my side via below snippet. After this tested, I think it’s not a good idea to set Outlook.Items in the ItemAdd Event. Would you please show me your goal of your checkMailFolder sub? Perhaps we’re able to find a better way instead of use it in ItemAdd Event.

     

    Have a good day,

     

    Tom

      Private Sub oNewMail_ItemAdd(ByVal item As Object) Handles oNewMail.ItemAdd
        checkMailFolder()
      End Sub
    
      Private Sub checkMailFolder()
        Dim items As Outlook.Items
        Try
          Console.WriteLine("Ready to get Items!")
          items = olInbox.Items
          Console.Write("Has ")
          Console.Write(items.Count)
          Console.WriteLine(" items!")
    
          For Each obj As Object In items
            Dim oItem As Outlook.MailItem = TryCast(obj, Outlook.MailItem)
            System.Console.WriteLine("Mail : " + oItem.Subject)
          Next
        Catch ex As Exception
          Console.WriteLine("There has occurred a exception : " + ex.Message)
          MsgBox(ex.Message)
        End Try
      End Sub
    


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 19, 2011 3:15 AM
    Moderator
  • My needs is the following:

    when I receive an email, I should scan the entire folder to gather some info.
    Silver Shadow

    Sunday, April 24, 2011 7:04 PM
  • Hi Silver_Shadow,

    I think you are able to use application.NewItemEx to handle your issue.

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 25, 2011 9:33 AM
    Moderator