Readonly after Read the Fileproperties

 

Hi,

i have wrote a Programm (vb.NET) to search of custom properties in a Directory. This program works with FileSystemWatcher so can i allways update the information in the list by any change the properties. I have sometimes (!!!) a problem: if a user want open any of the files in Solid Edge, then is es read only. After closing the program is all OK: the file can be opened.

I set for all Solid Edge Objects:

 

  Marshal.ReleaseComObject(obj)

or

  Marshal.FinalReleaseComObject(obj)

  obj = Nothing

and i start:

    GC.Collect()

    GC.WaitForPendingFinalizers()

    GC.Collect()

    GC.WaitForPendingFinalizers()

 

Thanks in advance for any help.

Best Regards

JR

 

Posted by: JR
Post date: 2/11/2009 2:54:59 AM

5 REPLIES

RE: Readonly after Read the Fileproperties

I'm assuming that you're using the SolidEdgeFileProperties API? If so, the PropertySets class has a Close() method. Are you using it?

 

The problem that you're seeing though I believe is the basic problem with .NET \ COM Interop. Even with ReleaseComObject(), the object may not get full released until the GC gets around to collecting the object. I constantly fight this exact problem with every .NET application that I write that integrates with Solid Edge.

 

Reply back on whether or not your using the Close() method. You may also post a .zip with as much of your project code as possible.

 

Posted by: Jason Newell
Post date: 2/11/2009 6:44:03 AM

RE: Readonly after Read the Fileproperties

I use the SolidEdgeFileProperties API, but i can not find the method Close() for PropertySets (i use Solid Edge V20 SP10). When i try to use the Method, i do not have any error (?). The Close() is not enough i must still start GC. Why can i not see the Method ?

 

The coding:

 

Sub Properties_Read(ByVal cDateiname As String)

On Error Resume Next

Dim propsets As SolidEdgeFileProperties.PropertySets = Nothing

Dim props As SolidEdgeFileProperties.Properties = Nothing

Dim prop As SolidEdgeFileProperties.Property = Nothing

Dim objDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing

Dim propSSE As SolidEdgeFramework.Properties = Nothing

Dim propSE As SolidEdgeFramework.Property = Nothing

Dim m As Integer

Dim sErrorText As String = ""

 

propsets = CreateObject("SolidEdge.FileProperties")

propsets.Open(cDateiname, True)

 

props = propsets("Custom")

If Not props Is Nothing Then

glGelesenAusSystem.Add(cDateiname & "; " & Now.TimeOfDay.ToString)

Else

'Datei direkt über SE ansprechen

If Not propsets Is Nothing Then

Marshal.FinalReleaseComObject(propsets)

propsets = Nothing

End If

objDoc = GetObject(cDateiname)

objDoc.Application.DoIdle()

propSSE = objDoc.Properties("Custom")

If Not propSSE Is Nothing Then

glGelesenAusSE.Add(cDateiname & "; " & Now.TimeOfDay.ToString)

Else

isError = True

sErrorText = "Zugriff auf Eigenschaften nicht möglich; " & Now.TimeOfDay.ToString

glGelesenAusSE.Add(cDateiname & " mit Fehler!!!; " & Now.TimeOfDay.ToString)

End If

End If

aProps(0) = cDateiname

For m = 3 To iUBound_aPropDef

aProps(m) = "0"

If Not (props Is Nothing) Then

For Each prop In props

If prop.Name = aPropDef(m) Then

aProps(m) = "1" + prop.Value

Marshal.ReleaseComObject(prop)

prop = Nothing

Exit For

End If

Marshal.ReleaseComObject(prop)

prop = Nothing

Next

ElseIf Not (propSSE Is Nothing) Then

For Each propSE In propSSE

If propSE.Name = aPropDef(m) Then

aProps(m) = "1" + propSE.Value

Marshal.ReleaseComObject(propSE)

propSE = Nothing

Exit For

End If

Marshal.ReleaseComObject(propSE)

propSE = Nothing

Next

End If

Next

 

If sErrorText "" Then aProps(3) = "0" & sErrorText

If Not prop Is Nothing Then

Marshal.FinalReleaseComObject(prop)

prop = Nothing

End If

If Not props Is Nothing Then

Marshal.FinalReleaseComObject(props)

props = Nothing

End If

props = Nothing

If Not propsets Is Nothing Then

 

propsets.close() 'NEW NOW HIER????, but close() not visible for propsets

 

Marshal.FinalReleaseComObject(propsets)

propsets = Nothing

End If

If Not propSE Is Nothing Then

Marshal.FinalReleaseComObject(propSE)

propSE = Nothing

End If

If Not propSSE Is Nothing Then

Marshal.FinalReleaseComObject(propSSE)

propSSE = Nothing

End If

If Not objDoc Is Nothing Then

Marshal.FinalReleaseComObject(objDoc)

objDoc = Nothing

End If

 

GC.Collect()

GC.WaitForPendingFinalizers()

GC.Collect()

GC.WaitForPendingFinalizers()

End Sub

 

Best Regards

 

JR

 

 

Posted by: JR
Post date: 2/11/2009 7:48:56 PM

RE: Readonly after Read the Fileproperties

They added the Close method fairly recently but I do not remember what version and service pack that it was added. They added it because of this exact problem. I would figure that SE v20 SP 10 would have it. You might also try running oleview.exe to see the Type Library definition of SolidEdgeFileProperties Type Library. Specifically, look at the IJPropertySets interface. It is where the Close() method is defined.

 

I believe the Close() method is your solution. We just have to figure out what version and service pack that they introduced it.

 

Posted by: Jason Newell
Post date: 2/11/2009 8:35:56 PM

RE: Readonly after Read the Fileproperties

Jason,

 

thank you very mutch.

The Method is with oleview.exe to see, so like an another method: "CreateCustonPropertySet()". What is this?

 

Best Regards

JR

 

Posted by: JR
Post date: 2/11/2009 9:37:02 PM

RE: Readonly after Read the Fileproperties

Hi,

 

i use now the Close() method, but i still have problems. The Loop

For Each prop In props

If prop.Name = aPropDef(m) Then

aProps(m) = "1" + prop.Value

Marshal.ReleaseComObject(prop)

prop = Nothing

Exit For

End If

Marshal.ReleaseComObject(prop)

prop = Nothing

Next

 

make that after close(), the File is not closed. If i do

GC.Collect()

GC.WaitForPendingFinalizers()

but not in the same sub (!) , is the File closed.

 

I changed the loop in this:

prop = props(aPropDef(m))

If Not prop Is Nothing Then

aProps(m) = "1" + prop.Value

Marshal.ReleaseComObject(prop)

prop = Nothing

End If

and the File is after "CLOSE()" closed now, without start the GC.

 

Best Regards

JR

 

 

 

 

Posted by: JR
Post date: 2/15/2009 8:41:50 PM