/// StatusText to set
private void UpdateStatus(string sStatus)
{
Trace.WriteLine(sStatus);
if (!LblStatus.CheckAccess()) //Check if correct Thread
{
LblStatus.Dispatcher.BeginInvoke(DispatcherPriority.Send, //Wrong Thread
new Action
return; //and leave
}
LblStatus.Content = sStatus; //only on correct thread the label is set
}
call like this:
1) start longrunning Task:
Task.Factory.StartNew(MyLong,TaskCreationOptions.LongRunning);
2) call Update Status from Longrunning Task
private void MyLong()
{
UpdateStatus("do some Long time ...");
}
No comments:
Post a Comment