I am writing a PowerPoint addin in C# with a TaskPane.
At a moment I want to print something on the pane - wait 5 sec - and print something different.
I have a problem with the waiting process.
If I use
System.Threading.Thread.Sleep(5000)
, I freeze all PowerPoint interface, not only my pane. PowerPoint interface and my task pane are one the same threadIf I use a
System.Timers.Timer
, then I have a second thread created and an error triggered saying that I am trying to access an object on a different thread.
This is my code for the 2nd case:
private void waitThisTime(int givenTime)
{
timer = new System.Timers.Timer(givenTime);
timer.Elapsed += OnTimedEvent;
timer.AutoReset = false;
timer.Enabled = true;
}
private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
DisplayMessage(currentState); // DisplayMessage modifies textbox and button displayed on the panel
}
Do you know how to freeze only the panel but without triggering an exception?
EDIT
This question here deals with access problem with multiple thread. My question is a little bit different because it deals with timer and I want to freeze only a part of my application (only panel not entire user interface)