c# - Application.Wait or Thread.Sleep -


i using backgroundworker.runasyn() run code on separate thread. hitting portion code iterates next line before previous line completed. should create separate backgroundworker handle that? or should use application.wait() or thread.sleep() not sure amount of time delay , i'd rather not have program sitting around waiting un-needed time not sure route take. here snippet of trouble-maker.

public form_main() {    initializecomponent();    backgroundworker1.workerreportsprogress = true;    backgroundworker1.dowork += new doworkeventhandler(backgroundworker1_dowork);    backgroundworker1_progresschanged += new progresschangedeventhandler(backgroundworker1_progresschanged); }  private void btnopenrefreshsave_click() {    backgroundworker1_runworkerasync(); }  private void backgroundworker1_dowork(object sender, doworkeventargs e) {    excel.application exapp;    excel._workbook exbook;    excel._worksheet exsheet;     exbook = (excel._workbook)(exapp.workbooks.open("c:\\book1.xlsx"));     exsheet = (excel._worksheet)(exbook.activesheet);    //this line of code times takes while    exbook.refreshall();    //end of trouble line    exbook.saveas("c:\\updated_book1.xlsx"); }  private void backgroundworker1_progresschanged(object sender, progresschangedeventargs e) {  } 

a few things come mind on here. try using similar below

if (application.calculationstate === xldone     finished calculating[enter link description here][1] 

another option (as others have suggested) changing background refresh property. quick scan of workbooks programmatically change you

foreach (wrksheet ws in workbook.wss) {     foreach (querytable table in ws.querytables)       table.backgroundquery = false; } workbook.refreshall(); 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -