[RESOLVED] instance of excel still in taskmanager
*EDIT*
nevermind i found a way to kill the instance that i don't want and to ensure that any other would be killed after the method finishes. I added the following see code...
ok hopefully someone can explain to me why the following is happening
first here's the code that i have, that i just started just want to make sure everything work the way it should for starters...
VB Code:
'Added Code
'*********************************************************************************
<DllImport("user32")> _
Private Shared Function SendMessage(ByVal hwnd As Integer, ByVal msg As Integer, _
ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
End Function
Private Const WM_DESTORY As Integer = &H2
'*********************************************************************************
Private Sub SaveToExcelFormat(ByVal filename As String, ByVal ds As DataSet)
Dim XlsApp As New Excel.Application
XlsApp.Visible = False
XlsApp.DisplayAlerts = False
Try
Dim XlsWorkBook As Excel.Workbook = XlsApp.Workbooks.Add
Try
Dim XlsWorkSheet As Excel.Worksheet = CType(XlsWorkBook.Worksheets(1), Excel.Worksheet)
Catch exSheet As Exception
MsgBox(exSheet.ToString)
End Try
XlsWorkBook.SaveAs(filename.Substring(0, filename.LastIndexOf(".")))
XlsWorkBook.Close()
Catch exBook As Exception
MsgBox(exBook.ToString)
End Try
If Not XlsApp Is Nothing Then
XlsApp.Quit()
'Added Code
'************************************
SendMessage(XlsApp.Hwnd, WM_DESTORY, 0, 0)
'************************************
XlsApp = Nothing
End If
GC.Collect()
End Sub
ok here's the issue, if you would call it that, that i'm running into. my app is a mdi i have two child windows open in it... i do a save as set it to excel and it running the method. now i have task manager open because i wanted to make sure that excel was starting up and shutting down. the first time i do the save as excel starts but does not shut down, if i do it again it starts and shuts down. i see the first instance in TM'er and it's still sitting there i see the other pop up in there and then go away. so my question is why is it that the first one stays and any other instance will actually quit??? :confused:
Re: [RESOLVED] instance of excel still in taskmanager
Resolved??
Then what was the solution.
I would like to know that too!!
Richard(newbie)
Re: [RESOLVED] instance of excel still in taskmanager
Its not quitting because of the two resources left instanciated - XlsWorkSheet XlsWorkbook. They need to be destroyed so the resources can be free'd before Excel can close.
@Richnl, see his remarks about the added api code ;) "'Added Code"