Hello_ everyone. First apologize if the question is not ask correctly and please correct me if I am wrong.
I am developing excel add-in using Visual Studio 2015. The project type is Excel 2013 and 2016 VSTO Add-in and my problem is that I want to show to users some indication that application is loading data at button click but UI is being updated when data is loaded and not before that ...
For example:
private void MyCustomMenuItem_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
{
Excel.Worksheet sheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
Excel.Shapes shapes = sheet.Shapes;
shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect1,
"Loading please wait ...",
"Arial",
16,
Office.MsoTriState.msoFalse,
Office.MsoTriState.msoFalse,
10,
10
);
// assume that on the following line is a long processing calculation
Thread.Sleep(3000);
// And the problem is that the Shape will show after 3 seconds
}
My problem is that the shape element will show after the thread is ready with its job in this case after 3 seconds. If on the place of Thread.Sleep(3000)
I have some code that will run 40 seconds it will show the text after 40 seconds ...
I know I'm doing something wrong and not updating the UI thread correctly ...
Question: How to update UI thread before a long processing task ?
Note: I'm using Microsoft.Office.Interop.Excel namespace for interacting with the excel application.
I did try to show a custom form with nothing but the text "Loading please wait" but again the form is showing after the long process ends ... Other thing that I tried is rising a custom event and trying to show something from the event handler but again no success ...
I want to avoid using Globals.ThisAddIn.Application.StatusBar = "Loading please wait ..."
method and do something more user friendly.
If someone can point me what am I doing wrong it will be great.
Thanks in advance_