内容へ移動
FiFiWiki2
FiFiWikiの第2版
ユーザ用ツール
ログイン
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
最近の変更
メディアマネージャー
サイトマップ
現在位置:
top
»
c.sharp
»
非同期
c.sharp:非同期
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
以下のコードの場合UIが動かなくなる ```c private void timer_MainSchedulerTimer_Tick(object sender, EventArgs e) { this.timer_MainSchedulerTimer.Enabled = false; /* 待つ */ Thread.Sleep(10 * 1000); Debug.WriteLine("waitt"); this.timer_MainSchedulerTimer.Enabled = true; } 以下のコードだと、UIは固まる。 asyncを付けても意味ない。 private async void timer_Tick(object sender, EventArgs e) { this.timer_MainSchedulerTimer.Enabled = false; /* 待つ */ Debug.WriteLine("Wait Start"); Thread.Sleep(10 * 1000); Debug.WriteLine("Wait End"); this.timer_MainSchedulerTimer.Enabled = true; } 以下のコードだと、UIはかたまらない。 (awaitが使用される場合は, asyncを付けていないとコンパイルエラーが発生する) private async void timer_Tick(object sender, EventArgs e) { this.timer_MainSchedulerTimer.Enabled = false; /* 待つ */ await Task.Run(() => { Debug.WriteLine("Wait Start"); Thread.Sleep(10 * 1000); Debug.WriteLine("Wait End"); }); this.timer_MainSchedulerTimer.Enabled = true; } ```
c.sharp/非同期.txt
· 最終更新: 2018/05/05 09:18 by
fifi
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
ページの名称変更
文書の先頭へ