ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   BackgroundWorker in Excel 2007 Managed Add-In (https://www.excelbanter.com/excel-programming/375912-backgroundworker-excel-2007-managed-add.html)

Chris Herring

BackgroundWorker in Excel 2007 Managed Add-In
 

I'm trying to use a background worker to execute a query and then display
the results in Excel in the workers RunWorkerCompleted event (similar to was
PivotTables do when you click "Show Details" on a cell).
Initially I had a problem that the RunWorkerCompleted event was not
executing on the main thread. I managed to get around this by using a
suggestion I found on the net, inserting the following call before calling
RunWorkerAsync:
AsyncOperationManager.SynchronizationContext = New
WindowsFormsSynchronizationContext()
Now the RunWorkerCompleted event runs on the main thread ok however if the
user is performing an action e.g. typing, when the worker thread completes
then any action that changes Excel in RunWorkerCompleted will raise a COM
exception. It does not wait for the user to complete their action before
calling the completed event.
Any suggestions on how to get around this issue?

Thanks
Chris

XL-Dennis

BackgroundWorker in Excel 2007 Managed Add-In
 
Hi Chris,

I'm not the person who have the right answer but would it be possible for
Your to catch the COM Exception in an error handling?

---------------
With kind regards,
Dennis
Weekly Blog .NET & Excel: http://xldennis.wordpress.com/
My English site: http://www.excelkb.com/default.aspx
My Swedish site: http://www.xldennis.com/


"Chris Herring" wrote:


I'm trying to use a background worker to execute a query and then display
the results in Excel in the workers RunWorkerCompleted event (similar to was
PivotTables do when you click "Show Details" on a cell).
Initially I had a problem that the RunWorkerCompleted event was not
executing on the main thread. I managed to get around this by using a
suggestion I found on the net, inserting the following call before calling
RunWorkerAsync:
AsyncOperationManager.SynchronizationContext = New
WindowsFormsSynchronizationContext()
Now the RunWorkerCompleted event runs on the main thread ok however if the
user is performing an action e.g. typing, when the worker thread completes
then any action that changes Excel in RunWorkerCompleted will raise a COM
exception. It does not wait for the user to complete their action before
calling the completed event.
Any suggestions on how to get around this issue?

Thanks
Chris



All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com