Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for Workbook.RefreshAll() (C#)

Tags:

c#

excel

I want to loop through a directory (using C#) and Refresh all Excel sheets in there. I use:

Workbook.RefreshAll();

How can I wait for the Workbook.RefreshAll() statement to finish?

The problem is: I open FileA, then Workbook.RefreshAll() and then open FileB - Refresh for FileA is terminated. The only solution I found is to call something like

System.Threading.Thread.Sleep(20000);

which I found very unlovely...

Does someone know a better way to wait?

like image 264
Frank Avatar asked Sep 13 '13 14:09

Frank


1 Answers

Updated 31.05.2016...

Thanks for your help. I found the following solution:

foreach (MSExcel.WorkbookConnection cnn in wb.Connections)
{
    if (cnn.Type.ToString() == "xlConnectionTypeODBC")
    {
        cnn.ODBCConnection.BackgroundQuery = false;
    }
    else
    {
        cnn.OLEDBConnection.BackgroundQuery = false;
    }
}

Frank

like image 147
Frank Avatar answered Oct 04 '22 16:10

Frank