Jump to content

Recommended Posts

Posted

Hi to All,

I have been desperately trying to find a solution to this problem. Now the problem is, I am trying to build a simple outlook com add in vb.net.

Every thing works fine but the moment I declare a mailitem object in goButton event, outlook stays in the memory. I have tried every thing to release the mail item object. but no matter what i do..outlook stays in the memory

the code i have written so far is

'''trying to release the objects

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

On Error Resume Next

' Notify the user you are shutting down, and delete the button.

goButton.Delete()

goButton = Nothing

GC.Collect()

GC.WaitForPendingFinalizers()

MsgBox("Our custom Add-in is unloading.")

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 = CType(application, Microsoft.Office.Interop.Outlook.Application)

addInInstance = addInInst

goInspectors = applicationObject.Inspectors

MsgBox("Our custom Add-in is loading.")

m_olExplorer = CType(applicationObject.ActiveExplorer, _

Microsoft.Office.Interop.Outlook.ExplorerClass)

m_objInsp = CType(applicationObject.ActiveInspector, _

Microsoft.Office.Interop.Outlook.InspectorClass)

End Sub

///adds a new button to the send email inspector

Private Sub goInspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles goInspectors.NewInspector

' Resume next since the FindControl call will generate an

' error if the button can not be found. We don't want to

' end, but add the button to the controlbar.

On Error Resume Next

Dim oSend As CommandBarButton

Dim oSendBar As CommandBar

oSendBar = Inspector.CommandBars("Standard")

oSend = CType(oSendBar.FindControl(Id:=oSendBar.Controls("Send Message").Id), CommandBarButton)

Dim oBar As CommandBar

oBar = Inspector.CommandBars("Standard")

goButton = CType(oBar.Controls.Item("Send & Track"), CommandBarButton)

goButton = CType(oBar.FindControl(Id:=oBar.Controls("Send & Track").Id), CommandBarButton)

If goButton Is Nothing Then

goButton = CType(oBar.Controls.Add(1), CommandBarButton)

With goButton

.Caption = "Send & Track"

.Style = MsoButtonStyle.msoButtonIconAndCaption

.Tag = "Send & Track"

.FaceId = oSend.FaceId

End With

End If

If CType(Inspector.CurrentItem, OlObjectClass) = OlObjectClass.olMail Then

goButton.Visible = True

Else

goButton.Visible = False

End If

oSend.Delete()

End Sub

''''here where the problem is i have declared a" objMailItem = CType(applicationObject.ActiveInspector.CurrentItem, MailItem)" ...if i omit this outlook closes fine other wise it stay in the momery. i have tried every thing to release the object but no matter what i do...nothing works

Private Sub goButton_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles goButton.Click

Try

MsgBox("Our CommandBar button was pressed!")

objMailItem = CType(applicationObject.ActiveInspector.CurrentItem, MailItem)

objMailItem = nothing

Catch ex As System.Exception

MsgBox("Error")

End Try

End Sub

i have even tried using the explorer close event to delete all object but still with no luck.

Please do help me as this project needs to be completed in next two days and I am just stuck here.

Please any information would be appreciated


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...