Excel instance (excel.exe) in task manager is not getting killed once button's execution is over.
Private Sub Extract_Click(sender As Object, e As EventArgs) Handles Extract.Click
Dim xlApp As New Excel.Application
Dim wbXLsource As Excel.Workbook
Dim wbXLtarget As Excel.Workbook
Dim shXLsource As Excel.Worksheet
Dim shXLtarget As Excel.Worksheet
Dim datestart As Date = Date.Now
wbXLsource = xlApp.Workbooks.Open(xlSourcePath)
wbXLtarget = xlApp.Workbooks.Open(xlTargetPath)
Dim dateEnd As Date = Date.Now
End_Excel_App(datestart, dateEnd)
End Sub
Private Sub End_Excel_App(datestart As Date, dateEnd As Date)
Dim xlp() As Process = Process.GetProcessesByName("EXCEL")
For Each Process As Process In xlp
If Process.StartTime >= datestart And Process.StartTime <= dateEnd Then
Process.Kill()
Exit For
End If
Next
End Sub
I tried using garbage collector concept also but excel instance is getting killed only after closing of app. I need to close the excel instance (excel.exe) after button execution gets over