I want to display information on screen for the user general view about process!
In the beginning, I used another thread, but this started an exception. Now I don't know. How can I change value on the screen simultaneously with another process?
How can I use GetElapsedTime to Show millisecond elapsed during the process?
WPF (XAML Code)
<StackPanel>
<Button Content="Start" Height="20" Width="50" HorizontalAlignment="Left" Name="ButtonStart" Click="ButtonStart_Click"/>
<Label Content="Elapsed Time (Milliseconds):"/>
<Label Name="LabelElapsedTime" Content="0"/>
</StackPanel>
public partial class MainWindow : Window
{
private StatusOfWork _StatusOfWork;
public MainWindow()
{
InitializeComponent();
}
private void ButtonStart_Click(object sender, RoutedEventArgs e)
{
_StatusOfWork = new StatusOfWork();
_StatusOfWork.CountN(10);
this.Close();
}
}
class StatusOfWork
{
public DateTime StartDateTime { get; set; }
public void CountN(int nTimes)
{
StartDateTime = DateTime.Now;
for (int i = 1; i <= nTimes; i++)
{
//doing anything
//Another Process
//...
Thread.Sleep(1000);
}
}
public double GetElapsedTime()
{
TimeSpan timeSpan = DateTime.Now - StartDateTime;
return timeSpan.TotalMilliseconds;
}
}