我制作makro来更改SolidEdge文件名。我有一个要更改此名称的循环。我在新线程中执行此操作,但在此行中获得了AccessViolationException:
objPropertySets.Open("C:\1.par", False)
这是我制作新线程的方式:
Dim T1 As New Thread(AddressOf ChangeName)
T1.Start()
这将启动一个功能:
Private Sub ChangeName()
Dim objPropertySets As SolidEdgeFileProperties.PropertySets = Nothing
Dim objProperties As SolidEdgeFileProperties.Properties = Nothing
Dim objProperty As SolidEdgeFileProperties.Property = Nothing
objPropertySets = New SolidEdgeFileProperties.PropertySets
objPropertySets.Open("C:\1.par".ToString, False)
objProperties = objPropertySets.Item("SummaryInformation")
objProperty = objProperties.Item("Title")
objProperty.Value = "abc"
objPropertySets.Save()
objPropertySets.Close()
End Sub
我尝试使用backgroundworker进行此操作,但是出现了相同的异常。
答案 0 :(得分:0)
添加的行: T1.SetApartmentState(System.Threading.ApartmentState.STA)