Backroundworker and Thread Sleep

Add-in Express™ Support Service
That's what is more important than anything else

Backroundworker and Thread Sleep
Excel Problems with BGW without Thread.Sleep 
Subscribe
Michael Kaden




Posts: 20
Joined: 2023-10-25
Hello Andrei,

hope you are well. My Excel AddIn is running well. In one Sub I do loops to solve problems and I use the Backgroundworker which speeds up this process considerable. Up to now this worked very well. Without changing any code I now observe 2 problems when the sub with the BGW is called which have not been there before.

1.) When I input a manual value in a cell which uses the AddIn and the BGW the sheet is locked I have to unlock it to continue.

2.) From time to time the Workbook freezes or shut down and opens immediately the same workbook.

When I put a thread.sleep(100) in that Sub before the BGW is called, the problem seems to go away.

Do you have any explanations for this behavior and what is the most stable remedy?

Thank you and kind regards.

Michael
Posted 12 Apr, 2025 17:32:56 Top
Andrei Smolin


Add-in Express team


Posts: 19120
Joined: 2006-05-11
Hello Michael,

I don't understand the description. What's "the sheet is locked"? Also, "input a manual value in a cell" may mean you are editing the cell either in the Formula Bar or in the cell itself. Such a scenario - if this is the scenario and if it affects your add-in - should be detected by your code, check https://www.add-in-express.com/creating-addins-blog/excel-check-user-edit-cell/.

Michael Kaden writes:
When I put a thread.sleep(100) in that Sub before the BGW is called, the problem seems to go away.


If this is the case of editing a cell, that would mean that Excel switching from the editing context to the context where your calls can be served.

These are guesses, though, as I don't understand the scenario.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Apr, 2025 10:03:03 Top