Hi...
thanks for reply
Sure... i tried it twice...
once with myItem as Outlook.ContactItem adn once with myItem as
Object...
both fails...
dont know why..
greetz HelixX²³
:
Did you remember to declare myItem as Outlook.ContactItem rather than
the
generic Object?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi...
So i tried this... but it fails also...
"
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
"
i = 250 as integer
Das COM-Objekt des Typs "System.__ComObject" kann nicht in den
Schnittstellentyp "Microsoft.Office.Interop.Outlook.ContactItem"
umgewandelt
werden. Dieser Vorgang konnte nicht durchgeführt werden, da der
QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle
mit
der
IID
"{00063021-0000-0000-C000-000000000046}" aufgrund des folgenden
Fehlers
nicht
durchgeführt werden konnte: Schnittstelle nicht unterstützt
(Ausnahme
von
HRESULT: 0x80004002 (E_NOINTERFACE)).
What am i doing wrong?
Maybe i should release the whole Outlook Application from my
harddrive...
(joke)
greets HelixX23
:
Try to remove everything from the loop and see if it runs Ok or
fails
with
the same problem.
myContactFolderItems = myContactFolder.Items
For i As Integer = 1 To myContactFolderItems.Count
myItem = myContactFolderItems.Item(i)
Marshal.ReleaseComObject(myItem)
Next i
Also, why do you keep recalculating
myContactFolderItems = myContactFolder.Items
*inside* the loop?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
I tried to declare myItem as Outlook.ContactItem but this fails
also...
something is wrong with the Garbage Collector... its not
collecting
anything...
I also tried to start the Garbage Collector before that function
and
after
the 245´s Item but it fails also.
are there maybe any working examples how to successfully
releaseComObjects
under an "exchange folder Items cycle"?
greets HelixX23
:
I can only guess tah t since you declare myItem as a generic
Object,
teh
compiler QI's it for IDispatch every timee and does not release
the
reference.
Can you try to declare it as ContactItem (assuming you do not
have
any
DLs
in that folder)?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi...
Thanks for the reply Dmitry.
something is getting better...
the failure changed the line...
maybe it is not explicitely declared enough??
Code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.VisualBasic.Information
Public Class SearchAndReplace
Public myContactFolder As Outlook.MAPIFolder '=
Outlook.Application.GetNamespace("MAPI").folders("Öffetnliche
Ordner").folders("Alle Öffentlichen Ordner").folders("EUKON
Kontakte")
Private Sub btnPickOLFolder_Click(ByVal sender As
System.Object,
ByVal
e
As System.EventArgs) Handles btnPickOLFolder.Click
Dim myOlApp As Outlook.Application =
CreateObject("Outlook.Application")
Dim myNamespace As Outlook.NameSpace =
myOlApp.GetNamespace("MAPI")
myContactFolder = myNamespace.PickFolder
If myContactFolder Is Nothing Then MsgBox("Sie haben
keinen
Ordner
ausgewählt...?") : Exit Sub
txtOutlookFolder.Text = myContactFolder.FolderPath
End Sub
Private Sub btnSearchAll_Click(ByVal sender As
System.Object,
ByVal
e
As
System.EventArgs) Handles btnSearchAll.Click
SearchALL()
End Sub
Private Sub SearchALL()
Dim myContactFolderItems As Outlook.Items =
myContactFolder.Items
Dim myItem As Object
Dim countItems As Integer = myContactFolderItems.Count
Dim myItemCategories As Object
Dim myItemFileAs As String
pgbSearchAndReplace.Enabled = True
pgbSearchAndReplace.Minimum = 0
pgbSearchAndReplace.Maximum =
myContactFolder.Items.Count
pgbSearchAndReplace.Value = 0
MsgBox("Items.Count = " & countItems)
For i As Integer = 1 To countItems
pgbSearchAndReplace.Value = i ' my Progressbar
Debug.Print("Memory: " & GC.GetTotalMemory(True))
Debug.Print("generate Object")
myContactFolderItems = myContactFolder.Items
myItem = myContactFolderItems.Item(i) ' old failure
has
passed
when "i as int = 250"
myItemCategories = myItem.Categories ' new failure
drops
here...
? not explicite enough?
myItemFileAs = myItem.FileAs.ToString
Debug.Print("Memory: " & GC.GetTotalMemory(True))
If TypeName(myItem) = "ContactItem" Then
If InStr(myItemCategories, txtSearch.Text,
CompareMethod.Text) Then
lstSearchResults.Items.Add(myItemFileAs &
" -
" &
myItemCategories)
End If
Else
MsgBox(TypeName(myItem))
End If
' Try to release ComObjects
ReleaseMyComObject(myItem)
ReleaseMyComObject(myContactFolderItems)
ReleaseMyComObject(myItemCategories)
ReleaseMyComObject(myItemFileAs)
If i Mod 245 = 0 Then
' --- GC starten
Debug.Print("Memory: " &
GC.GetTotalMemory(True))
Debug.Print("GC starting")
GC.Collect()
GC.WaitForPendingFinalizers()
Debug.Print("Garbage collected")
Debug.Print("Memory: " &
GC.GetTotalMemory(True))
End If
Next i
pgbSearchAndReplace.Value = 0
pgbSearchAndReplace.Enabled = False
End Sub
Public Sub ReleaseMyComObject(ByVal myCOMObject As Object)
Try
If Not myCOMObject Is Nothing Then
Do
If Marshal.ReleaseComObject(myCOMObject) =
0
Then
Debug.Print("Object released")
Exit Do
End If
Loop
End If
Catch ex As Exception
Debug.Print("Can't release ComObject" & vbCrLf &
ex.Message)
End Try
myCOMObject = Nothing
End Sub
End Class
What am i doing wrong?
greets HelixX23
:
Do not use multiple dot notation (e.g.
myContactFolder.Items.Count)
as
the
compiler creates implicit variables to hold the intermediate
results.
Use explicit variables and explicitly release them.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
message
In my Environment Marshal is not defined
I´m using Visual Studio 2005 VBA Outlook Addin to get this
working..
So i used the
System.Runtime.InteropServices.Marshal.ReleaseComObject
referenced function to release my COM Object...
but.. it does not work..
Code:
For i As Integer = 1 To myContactFolder.Items.Count
Debug.Print("generate Object")
Debug.Print("Speicher: " &
GC.GetTotalMemory(True))
Dim myItem As Outlook.ContactItem =
myContactFolder.Items.Item(i) ' here drops the failure when
"i"
reaches
"249
as int"
Debug.Print("Speicher: " &
GC.GetTotalMemory(True))
If
Microsoft.VisualBasic.Information.TypeName(myItem)
=
"ContactItem" Then[/QUOTE][/QUOTE][/QUOTE]