我在WPF中有一个非常简单的应用程序。它有一些按钮,文本框和形状。 一些按钮打开另一个WPF窗口,而其他按钮则显示消息框。
我如何知道申请的回复时间?换句话说,如何衡量点击按钮和显示另一个窗口之间的时间?
答案 0 :(得分:0)
这将测量从击中ctor到 甚至可以将秒表传递给窗户public partial class Window1 : Window
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
public Window1()
{
sw.Start();
System.Threading.Thread.Sleep(900);
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
sw.Stop();
tbTime.Text = sw.ElapsedMilliseconds.ToString();
}
}
public partial class Window1 : Window
{
System.Diagnostics.Stopwatch sw;
public Window1()
{
sw = new System.Diagnostics.Stopwatch();
sw.Start();
System.Threading.Thread.Sleep(900);
InitializeComponent();
}
public Window1(System.Diagnostics.Stopwatch SW)
{
sw = SW;
if (!SW.IsRunning) sw.Restart();
System.Threading.Thread.Sleep(900);
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
sw.Stop();
tbTime.Text = sw.ElapsedMilliseconds.ToString();
}
}