SpreadsheetGear
BeginUpdate Method
See Also  Example Send Feedback
SpreadsheetGear Namespace > IWorkbookSet Interface : BeginUpdate Method

Interrupts background calculation if necessary, acquires an exclusive lock on the workbook set, and suspends painting and events until EndUpdate is called.

Syntax

Visual Basic (Declaration) 
Sub BeginUpdate() 
C# 
void BeginUpdate()

Example

Demonstrate using a workbook set in a thread safe manner when accessing the SpreadsheetGear API many times.
C#Copy Code
void DoSomeThreadSafeWorkQuickly(IWorkbookSet workbookSet)
       {
           
// Interrupt background calculation if necessary, acquire an
           
// exclusive lock on the workbook set and suspend events and
           
// painting.
           
workbookSet.BeginUpdate();

           
try {
               
// Do a lot of work...
           }
           
finally {
               
// Release the lock on the workbook set, start background
               
// calculation if appropriate and repaint controls.
               
workbookSet.EndUpdate();
           }
       }
    
Visual BasicCopy Code
Sub DoSomeThreadSafeWorkQuickly(ByVal workbookSet As IWorkbookSet)
            ' Interrupt background calculation if necessary, acquire an
            ' exclusive lock on the workbook set and suspend events and
            ' painting.
            workbookSet.BeginUpdate()

            Try
                ' Do a lot of work...
            Finally
                ' Release the lock on the workbook set, start background
                ' calculation if appropriate and repaint controls.
                workbookSet.EndUpdate()
            End Try
        End Sub 'DoSomeThreadSafeWork

Remarks

This method is thread safe.

Use BeginUpdate and EndUpdate when making a large number of changes to a workbook set which is attached to one or more Windows Forms components from SpreadsheetGear. Doing so will typically result in significant performance improvements when accessing the SpreadsheetGear API many times to change the workbooks in a workbook set. However, all events which would have been fired before EndUpdate is called will be lost, and all Windows Forms components from SpreadsheetGear which are attached to the workbook set will be completely repainted after EndUpdate is called.

An exception will be thrown if UnwindLock is called after a call to BeginUpdate and before a call to EndUpdate. Changing the workbook set associated with any Windows Forms component from SpreadsheetGear generates a call to UnwindLock, therefore the workbook set of a Windows Forms component cannot be changed when using BeginUpdate.

BeginUpdate essentially detaches a workbook set from any SpreadsheetGear Windows Forms components, temporarily making performance similar to using a workbook set with no attached user interface.

BeginUpdate calls GetLock to acquire a lock on the workbook set.

EndUpdate must be called for each call to BeginUpdate. The recommended best practice is to call BeginUpdate followed by a try block where work is done, and then call EndUpdate in a finally block.

Requirements

Platforms: x86 and x64 versions of Windows 2000, Windows XP, Windows Vista, Windows 7, Windows Server 2003 (including R2) and Windows Server 2008 (including R2). SpreadsheetGear 2009 requires the Microsoft .NET Framework 2.0 and supports .NET 3.0 and .NET 3.5.

See Also

Copyright © 2003-2009 SpreadsheetGear LLC. All Rights Reserved.Help Powered by Innovasys   
SpreadsheetGear is a registered trademark of SpreadsheetGear LLC.
Microsoft, Microsoft Excel and Visual Studio are trademarks or registered trademarks of Microsoft Corporation.