Update text in StatusBar in wpf using C#
Posted
by Archie
on Stack Overflow
See other posts from Stack Overflow
or by Archie
Published on 2010-04-30T09:47:39Z
Indexed on
2010/04/30
10:17 UTC
Read the original article
Hit count: 1062
hello,
I have a TextBox in StatusBar in wpf which i want to update.
I have a list of files in ListBox. On each file I would be doing some operation by calling say method ProcessFile(). So whenever the file processing is completed I want to show that file's name in the StatusBar text.
I have tried something like this:
private void button_Click(object sender, RoutedEventArgs e)
{
statusBar.Visibility = Visibility.Visible;
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(TimeConsumingMethod), frame);
Dispatcher.PushFrame(frame);
statusBar.Visibility = Visibility.Collapsed;
}
public object TimeConsumingMethod(Object arg)
{
((DispatcherFrame)arg).Continue = false;
foreach (string fileName in destinationFilesList.Items)
{
txtStatus.Text = fileName.ToString();
//Assume that each process takes some time to complete
System.Threading.Thread.Sleep(1000);
}
return null;
}
But i can only see the last file's name in the StatusBar. Whats wrong with the code? Can somebody correct it? Thanks.
© Stack Overflow or respective owner