Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using BackgroundWorker and create a reference to excel. Problem is I can not seem to release the reference. It still shows up in task manager and does not release until the application closes.

 

Any suggestions?

Posted

xlApp.Quit()

xlApp = Nothing

 

Normally this works, but I can not seem to get it to work with a new thread with backgroundworker.

 

Code Example 1:

 

This code within a module works. Viewing task manager excel starts and exits. I use this all the time.

 

Sub mExcelReport()

Dim xlApp as New Excel.Application

Dim xlSheet as New Excel.WorkSheet

 

xlApp.Workbooks.Add

xlSheet = xlApp.ActiveSheet

 

xlSheet.Range("A2").Value = "Hello"

 

xlApp.Quit()

 

xlApp = Nothing

 

End Sub

 

 

Code Example 2:

 

When I run it with Backgroundworker the Excel Reference does not release. Excel is still visible with tasks manager. This is causing issues when other process run.

 

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

 

mExcelReport()

 

 

End Sub

 

Sub mExcelReport()

Dim xlApp as New Excel.Application

Dim xlSheet as New Excel.WorkSheet

 

xlApp.Workbooks.Add

xlSheet = xlApp.ActiveSheet

 

xlSheet.Range("A2").Value = "Hello"

 

xlApp.Quit()

 

xlApp = Nothing

 

End Sub

 

 

Any ideas?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...