---
# System prepended metadata

title: C# Window を 表示してすぐ閉じるまでの 処理時間計測 2022-03-29
tags: [WinForm, C#, WPF, Window, 処理時間計測]

---

---
lang: ja-jp
breaks: true
---
# C# Window を 表示してすぐ閉じるまでの 処理時間計測 2022-03-29

* .NET Framework WPF Window ：0.22秒～0.28秒
* .NET Framework Form　　　　：0.14秒～0.18秒



## WPF

```csharp=
Stopwatch sw = new Stopwatch();
sw.Start();

Window1 win = new Window1();
win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
win.Owner = this;
win.ShowDialog();    // Loaded で Close();

sw.Stop();

textBox1.Text = sw.Elapsed.ToString();
```

## Form

```csharp=
Stopwatch sw = new Stopwatch();
sw.Start();

Form2 form = new Form2();
form.StartPosition = FormStartPosition.CenterParent;
form.ShowDialog();    // Shown で Close();

sw.Stop();

this.textBox1.Text = sw.Elapsed.ToString();
```

###### tags: `C#` `Window` `処理時間計測` `WPF` `WinForm`
