I am working on creating an excel report in VB.Net
. The report created successfully and i killed the processes at the end. But when the same report runs simultaneously from different machines i.e it is used by multiple users, it kills all the processes and only one user is able to create the report.
Can you please suggests how can i close only the specific excel process once it is created. Below is my code
If Not _xlApp.Workbooks Is Nothing Then
For Each wb In _xlApp.Workbooks
wb.Close(False)
Next
_xlApp.Workbooks.Close()
End If
_xlApp.DisplayAlerts = False
_xlApp.Quit()
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
If _oSheet IsNot Nothing Then
Runtime.InteropServices.Marshal.ReleaseComObject(_oSheet)
End If
Runtime.InteropServices.Marshal.ReleaseComObject(_oBook)
_xlApp.Quit()
Runtime.InteropServices.Marshal.ReleaseComObject(_xlApp)
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
Dim proc As Diagnostics.Process
For Each proc In Diagnostics.Process.GetProcessesByName("EXCEL")
Try
proc.Kill()
Catch ex As Exception
End Try
Next
The problem is that i cannot identify the PID of the processes that should be closed when an excel is created.