C#2.0の匿名メソッド

6 views
Skip to first unread message

Sho Hashimoto

unread,
Oct 23, 2007, 6:47:28 AM10/23/07
to oklab...@googlegroups.com
ControlクラスのInvokeメソッドで匿名メソッドを使うには?[2.0のみ、C#]
- @IT
http://www.atmarkit.co.jp/fdotnet/dotnettips/660anonymethod/anonymethod.html

GUIとは別スレッドからGUI要素を変更する時
Form.Invoke()というメソッドでやらないとスレッドのデッドロックが起こるので

こうとか
MethodInvoker d = delegate() { textBoxMsg.Text += "hogehoge"; };
this.Invoke(d);

こう書くと1行で書ける
this.Invoke((MethodInvoker) delegate() { textBoxMsg.Text += "hogehoge"; });


なんか引数なしのdelegateとか、引数stringだけのdelegateとか作ったり
GUI要素1個変えるだけの関数を大量に作ったりしてたけどこれですっきりする。

--
橋本 翔(Sho Hashimoto)
sho...@sfc.keio.ac.jp
http://shokai.org/

Reply all
Reply to author
Forward
0 new messages