Mathias Brandewinder on .NET, F#, VSTO and Excel development, and quantitative analysis / machine learning.
2. August 2011 16:06

When working with Excel, it is common to use small optimization tricks, like setting Excel.ScreenUpdating to false to avoid un-necessary screen refreshes, during lengthy operations – something along these lines:

public void DoJob(Worksheet  worksheet)
{
var excel = worksheet.Application;

var initialScreenUpdating = excel.ScreenUpdating;
var initialCursor = excel.Cursor;

excel.ScreenUpdating = false;
excel.Cursor = XlMousePointer.xlWait;

// do stuff

excel.ScreenUpdating = initialScreenUpdating;
excel.Cursor = initialCursor;
}

This is a good outline of what we would like to happen, but as is, this code has limitations. We would like to be certain that whenever we capture the state, the final two lines, which reset the state to what it was originally, are executed.

More...

#### Need help with F#?

The premier team for
F# training & consulting.