views:

133

answers:

1

Hi,

I have created an Add-In in C# that implements user defined functions for Excel. These UDF's return immediately, but they control background asynchronous procedures.

These procedures have status that needs to be monitored and presented to Excel. I have chosen to display the status using checkboxes.

A background thread then updates the checkbox linked to a particular background procedure.

I have wrapped the calls to the Excel model with a try/catch block and retry the call after a delay in case an exception is thrown by Excel not being ready. This mechanism works correctly as well.

The problem is that sometimes, even though the code to modify a checkbox runs successfully, the checkbox itself is not modified in Excel.

I have done a sanity check on the checkbox attributes that I am changing and can see they haven't changed in the logs:

                checkBox.Value = false;
                checkBox.Interior.Color = 0x00DDDDDD; // light grey in AABBGGRR format
                checkBox.Caption = "Off";

                // this sometimes prints the values the checkbox had before the above line
                LogDebug( "Color: " + checkBox.Interior.Color + " Value:" + checkBox.Value + " caption:" + checkBox.Caption );

This only happens in Excel 2003. In Excel 2007 the problem as never ocurred.

I've tried fiddling with Application.ScreenUpdating, Application.Interactive, modifying the COM Apartment thread attributes without any luck. This is not a concurrency issue because I am not changing the checkbox attributes anywhere else.

As anybody had a similar experience?

Thanks!

A: 

Well, I am hacking a quick fix that works OK for now, though I still don't understand why this happens.

For now, if the set values are not correct after setting them, I treat that as an exception and put the request in a background thread for a future try.

The code then iterates until it manages to update the checkbox.

Don't like it, but it gives out correct behaviour.

Eurico