المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# Excel and Threading



C# Programming
08-28-2009, 09:15 PM
Hi There,

I have a background worker thread on my Form.

In 'DoWork' A call is made from the thread to pump data out to Excel. The visible property of my Excel Application is set to false until 'RunWorkerCompleted' (there may be a lot of data and the users don't want to see it being churned out) when visible is set to true, I also use the .Activate method :

excelApplication.Visible = true;
((Microsoft.Office.Interop.Excel._Workbook)excelWorkbook).Activate();

Everything works fine except the Excel appears behind my form - not the front.. annoying .. in addition its only happening on my tester's machine (typical!) and not mine. It is the last code that executes.

excelApplication and excelWorkbook are in a different class which I suspect is the root of the issue, also it needs to be inside the thread so the UI is not affected when the form is moved around and such like.

Any ideas?

Thanks very much

Jon