I've read every post I could find on this, and THOUGHT I was handling it correctly. But I've got one Excel COM process that still keeps hanging around. I know where it is (see COMMENT IN caps), and I know why it's hanging around (it uses a Split(Range) call, creating two COM objects).
But I still can't figure out how to kill the second object. I thought waiting for pending finalizers by the GC would take care of both of them, but no luck. What am I missing?
Private Sub PopulateSensorSizes(ByVal newContFlag As Boolean)
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim Values() As String
oExcel = New Excel.Application 'Create a new instance of Excel
oBook = oExcel.Workbooks.Open(ControllerParamFilePath) 'Get correct existing Controller file
oSheet = oExcel.Worksheets(1)
oExcel.Visible = False 'Don't show it to the user
'Show sensor sizes
Values = Split(oSheet.Range("B2").Value, "," & " ") 'Split text. TWO COM OBJECTS LAUNCHED HERE
Dim i As Integer
For i = 0 To UBound(Values)
SelectSensorSize.Items.Add(Values(i)) 'Add all integer sensor sizes to ListBox1
Next i
oBook.Close() 'Disconnect from Excel and end processes
oExcel.Quit()
oBook = Nothing
oExcel = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
SelectSensorSize.Items.Add("Enter new sensor size")
End Sub
EDIT: I tried rewriting this to attempt to eliminate the "two dot" issue, but I am getting the same result: one process left running.
Private Sub PopulateSensorSizes(ByVal newContFlag As Boolean)
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim Values() As String
Dim ValRange as Excel.Range
oExcel = New Excel.Application 'Create a new instance of Excel
oBook = oExcel.Workbooks.Open(ControllerParamFilePath) 'Get correct existing Controller file
oSheet = oExcel.Worksheets(1)
oExcel.Visible = False 'Don't show it to the user
'Show sensor sizes
ValRange = oSheet.Range("B2")
Values = Split(ValRange.Value, "," & " ") 'Split text. TWO COM OBJECTS LAUNCHED HERE
Dim i As Integer
For i = 0 To UBound(Values)
SelectSensorSize.Items.Add(Values(i)) 'Add all integer sensor sizes to ListBox1
Next i
oBook.Close() 'Disconnect from Excel and end processes
oExcel.Quit()
oBook = Nothing
oExcel = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
SelectSensorSize.Items.Add("Enter new sensor size")
End Sub