Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / December 2005

Tip: Looking for answers? Try searching our database.

Outlook + Webservice - Listener disappears

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
anders@cichlids.dk - 16 Dec 2005 11:50 GMT
I try to make a outlook-addin that integrates with a webservice....

I create one folder with ten subfolders. I add a Listener to each
folder....

When a email is dropped in one of these subfolders, an event is called.
This event calls a Webservice....

After I have dropped ex. 6-7 emailitems in my foldes, my listener
disappers ...

Any ideas ?

My code :

Public Class Connect

    Implements Extensibility.IDTExtensibility2

    Dim applicationObject as Object
   Dim addInInstance As Object

   Shared Service As New MyWebservice.outlookService
   Shared CookieContainer As New Net.CookieContainer

   Dim OutlookApp As Outlook.Application

   Dim NewFolder As Outlook.MAPIFolder

   Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
   End Sub

   Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
   End Sub

   Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
   End Sub

   Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
   End Sub

   Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
       applicationObject = application
       addInInstance = addInInst

       outlookapp = CType(applicationObject, Outlook.Application)

       Dim oNS As Outlook.NameSpace = OutlookApp.GetNamespace("MAPI")
       Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
       Dim RootFolder As Outlook.MAPIFolder = CType(oInbox.Parent,
Outlook.MAPIFolder)

       Dim Caption As String = "Testmappe"

       'If already Exsist, Then remove
       Try
           Dim i As Integer
           Dim CurrentFolder As Outlook.MAPIFolder

           If RootFolder.Folders.Count > 0 Then
               For i = 1 To RootFolder.Folders.Count
                   CurrentFolder = RootFolder.Folders.Item(i)

                   If String.Compare(CurrentFolder.Name, Caption,
False) = 0 Then
                       RootFolder.Folders.Remove(i)
                   End If
               Next
           End If
       Catch ex As Exception
           Windows.Forms.MessageBox.Show(ex.ToString)
       End Try

       'Add TestFolder to root
       NewFolder = RootFolder.Folders.Add(Caption)

       'Add 10 subfolders
       For n As Integer = 1 To 10
           Dim folder As Outlook.MAPIFolder =
NewFolder.Folders.Add("folder " & n)

           'Add Eventlistener
           AddHandler folder.Items.itemadd, AddressOf
Me.MyListener.DoEvent
       Next

       Service.CookieContainer = Me.CookieContainer

   End Sub

   Dim MyListener As New Listener

   Private Class Listener

       Public Sub DoEvent(ByVal item As Object)
           Windows.Forms.MessageBox.Show("item dropped on folder")

           Service.IsLoggedIn()
       End Sub

   End Class

End Class
Dmitry Streblechenko - 19 Dec 2005 19:11 GMT
folder.Items collection for all folders in question must be stored in a
global/class variable(s) to make sure it is referenced and the GC will not
release it.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

>I try to make a outlook-addin that integrates with a webservice....
>
[quoted text clipped - 108 lines]
>
> End Class
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.