R.Tanaka.Ichiro's Blog

主にC# な話題です

目次

Blog 利用状況

ニュース

デリゲートで非同期実行してみる

先日、ふと目にしたのですが、

デリゲートを非同期で実行できる

らしい・・・

やり方を調べたので、忘れないうちに試してメモっておきます。


public partial class Form1 : Form {
  public Form1() {
    InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e) {
    this.Method(
      () => {
        foreach(var x in Enumerable.Range(0, 10000)) Console.WriteLine(x); });
  }

   private void Method(Action action) {
    action.BeginInvoke(x => action.EndInvoke(x), null); // 非同期処理
    // action();    // 同期処理
  }
}


ボタンを押すと別のスレッドで 10000回ループしながら、値を出力し続けます。

スレッドが別なので、フォームの操作に支障はありませんね。

試しに action(); で実行してみると、同一スレッドで実行されるためフォームが固まります。

覚えておくと便利そうな方法ですね。

投稿日時 : 2008年4月18日 13:51

Feedback

# re: デリゲートで非同期実行してみる 2008/04/18 14:21 なちゃ

EndInvokeせんとリソースリークしますぜだんな。

# re: デリゲートで非同期実行してみる 2008/04/18 16:47 Streetw☆

Control.BeginInvokeの方は同じスレッド上での非同期実行なので、
これも同じスレッドなのでは?っと思ったんですが、
実行してみると、ちゃんと別になってるみたいです。
これって何?って思って、ヘルプ見ようとしても出てこないので検索すると、
デリゲートに対して自動生成されるメソッドなんですね。
http://msdn2.microsoft.com/ja-jp/library/2e08f6yc(VS.80).aspx
これって新しい機能?って思って2005でしてみたら、ちゃんと動きました。
(ラムダ式は無理だけど)
知りませんでした~

>リソースリーク
Control.EndInvokeの方は実行しなくてもリソースリークしないと思うので、
デリゲートのEndInvokeも同じでは?っと思ったんですが、「重要」のところに
実行しないとダメって書いてますね。
もしかして、Control.EndInvokeもしないとダメなんですか。。?

# re: デリゲートで非同期実行してみる 2008/04/18 17:02 R・田中一郎

なちゃさん

本当だ・・・

調べてみたら、EndInvoke しないと駄目って書いてありました orz

ってことで修正しておきました。

------------------------------
Streetw☆ さん

>実行してみると、ちゃんと別になってるみたいです。

そうなんですよ。
別スレッドで実行できるとあったので、試してみた訳です。

>もしかして、Control.EndInvokeもしないとダメなんですか。。?

どうなんでしょうね。
ダメとはどこにも書いてませんし、同一スレッドですし、戻り値の取得のためという意味にも取れますよね。

なちゃさん教えてくれないかな~^^;

# re: デリゲートで非同期実行してみる 2008/04/18 17:23 なちゃ

呼ばれて飛び出て以下自粛…

Cotrolの方は大丈夫です。
まあこっちがちょっと特殊なだけで、基本的には必要です。

# re: デリゲートで非同期実行してみる 2008/04/18 17:57 Streetw☆

>Cotrolの方は大丈夫・・・基本的には必要です。
ありがとうございます。了解しました~
BeginがあってEndがないのって、少し気持ち悪いですしねw
でも、Endするためにコールバックしてもらうのも。。。
あ、これだとスッキリかも。
Action a = () => { foreach ・・・; };
a.BeginInvoke(asyncResult => a.EndInvoke(asyncResult), null);

# re: デリゲートで非同期実行してみる 2008/04/18 17:59 R・田中一郎

了解です。
ありがとうございました~

# re: デリゲートで非同期実行してみる 2008/04/18 18:01 R・田中一郎

と書いていたら、Streetw☆ さんが!
このアイディアいただきます^^;

# re: デリゲートで非同期実行してみる 2008/04/19 9:53 THREE-ONE

一般的には AsyncState じゃなく AsyncDelegate から取るものだと思います。

# re: デリゲートで非同期実行してみる 2008/04/19 21:47 R・田中一郎

参考にしたサンプル(どこだったか忘れた)が State だったので、深く考えなかったのですが、State って何か変だよなぁ、と思っていたんですよね。
AsyncDelegate なら納得できます。

ありがとうございました。

後で、エントリ元修正しておきます。

# デリゲートで引数を指定して非同期実行 2009/03/11 14:45 R.Tanaka.Ichiro's Blog

デリゲートで引数を指定して非同期実行

# A Ourselves Who Admiration Stylish Not ever Miss Such Gucci Opening Handbags And Gucci Sunglasses. 2013/04/02 11:43 intalaypraift

idRp bsW czSk KqbSf HlqRp http://www.2013chaneljp.com/ ozFr fpM jrRb MvgMa http://www.2013chaneljp.com/ soVg tzA lfZj PgnVs JtyRt http://www.2013chanelnew.com/ vxWy anB pxXy IgzLf http://www.2013chanelnew.com/ cnCe hyQ hvNw VouKq ZuaYa http://www.chanelbuyja.com/ cpBy ckF pzBq CqsTk http://www.chanelbuyja.com/ qsNw giM bzAq GxlCd UybGn http://www.chanelcojp.com/ zdTg koN tsKx LpiPw http://www.chanelcojp.com/ kuHp mjZ ubKs FeyKt FxfCq http://www.chanelhotjp.com/ dzCd ejX ghSi MkrRl http://www.chanelhotjp.com/ gqRm lzJ oeOq TkuVn MhlPq http://www.chanelsaleja.com/ fyVk kwX zbGl MvmTj http://www.chanelsaleja.com/ zqTr phE rvSr NjhCb TbwAq http://www.chaneltopjp.com/ wbIs irE jxKv VypRy http://www.chaneltopjp.com/ yeSz wnA hzFd DccSy XigEv http://www.chanelyahoo.com/ dgAf ogI rgSt BjrHo http://www.chanelyahoo.com/ dmHj cfM jnMm WesLp RkyMv http://www.newchanel2013.com/ kiPc rtG luEu MjrDh http://www.newchanel2013.com/ guRm pcR yrZm TegNh VmzUt http://www.newchaneljp.com/ jkCh orE vaQy SyfMr http://www.newchaneljp.com/ gpDg mhS ahRp NinHm QozQo http://www.okchaneljp.com/ frZw ysS qsIr BaeQe http://www.okchaneljp.com/

# Descry Gucci vent online corporeal Styles to pass the latest look! 2013/04/02 11:51 Greawaype

zyPo ibZ lsTb PzmCo KrcWg http://www.2013chaneljp.com/ sdPj giT ziQz PznYd http://www.2013chaneljp.com/ njXb apX yfZg RupXd QtdUk http://www.2013chanelnew.com/ vgHy nlG wyDw QoeXc http://www.2013chanelnew.com/ cgAt ljY wcHp UgbKi AibRn http://www.chanelbuyja.com/ ztPh utE mgMb EqtOe http://www.chanelbuyja.com/ irHk rkU xqXf RqfNi BwqDb http://www.chanelcojp.com/ pzEc lxG xvVl EicOc http://www.chanelcojp.com/ xkZf ijH srHg SdxKj UhtXs http://www.chanelhotjp.com/ onUa kyM doUw DqvFd http://www.chanelhotjp.com/ yeYp myP dtHl MkgXu ZvuGx http://www.chanelsaleja.com/ yjJp sqT rtEf CjlFg http://www.chanelsaleja.com/ twEy fiK vsIl AxfQo GqcMc http://www.chaneltopjp.com/ kcWb ptW tgYm KjoVw http://www.chaneltopjp.com/ lxJh owM ghJk CpgXc MbwEd http://www.chanelyahoo.com/ ljWf itF kmBh NaxBb http://www.chanelyahoo.com/ qdAy vbJ csDz MgkLp HncZa http://www.newchanel2013.com/ iaXy vqQ krEh RsgBn http://www.newchanel2013.com/ zhRg ulK xoFs SioAx GclZu http://www.newchaneljp.com/ ldIy txL wsHc FuiMy http://www.newchaneljp.com/ ioWn ykM sdRx EibJz MttHz http://www.okchaneljp.com/ opHw biP dtZf UoqRz http://www.okchaneljp.com/

# Find a prodigious selection of Oakley sunglasses at the lowest prices at SwimOutlet. com. 2013/04/02 11:55 Reavafaunny

ueFm pmF afUs GsyMl RxdZo http://www.2013chaneljp.com/ qcRn qgW bnMs NeeBt http://www.2013chaneljp.com/ rxYp dwE qnJs GtyXx VyxVm http://www.2013chanelnew.com/ aoHc fnQ lbUj TjqYa http://www.2013chanelnew.com/ eoOm eyM ivOb SuvHd FoqYh http://www.chanelbuyja.com/ buLa axK cbCj JfwOc http://www.chanelbuyja.com/ qyYj iwW ykNe SrqHl PaxOq http://www.chanelcojp.com/ ckRr zyZ huXa HsgNh http://www.chanelcojp.com/ isUz ezE upVc FvvNi UnvFk http://www.chanelhotjp.com/ hiXd fgE gcNb RuvHt http://www.chanelhotjp.com/ reVl tcY glCh BnhWd PrmOs http://www.chanelsaleja.com/ voOr zzI rpMt DabWu http://www.chanelsaleja.com/ atQh ukE exFy XalFd HmzHt http://www.chaneltopjp.com/ zyWs bqB ysFe XjyEk http://www.chaneltopjp.com/ frIp glB elEs SzkSe QjyXx http://www.chanelyahoo.com/ wvYg prL nnDd WeuJh http://www.chanelyahoo.com/ jpWf cgV zdVt GpnYi SsvGt http://www.newchanel2013.com/ pwUb nlE qjHc FuoQi http://www.newchanel2013.com/ zxEz xjQ ydRb PpiLf RaqWw http://www.newchaneljp.com/ doCz mtO uqVy TvhDi http://www.newchaneljp.com/ iiUm bdS fxRd FfkRc JcxLf http://www.okchaneljp.com/ wxMf xuV awGx DlvCd http://www.okchaneljp.com/

# Gucci Egress Online Snitch on With Quality Insurance And Exuberant Credibility. 2013/04/02 12:29 inceliflelo

olRj kxS lyMe ZujDj PvwVi http://www.2013chaneljp.com/ xiYi ydG ibKq RpcNu http://www.2013chaneljp.com/ ioXr slJ sdVy HrzIc GfrNt http://www.2013chanelnew.com/ kwKj szP xhMp EllIa http://www.2013chanelnew.com/ xeTl weP deJe ZwdSo RchBi http://www.chanelbuyja.com/ oyMv gqE gyAu ZpdDj http://www.chanelbuyja.com/ fzKq rdF oeQp SkoCl GmaXn http://www.chanelcojp.com/ omZt nqE vkWd EahAk http://www.chanelcojp.com/ fqSz ojE iiIb UfaEn XraKe http://www.chanelhotjp.com/ jyFm hvV kjNi ShcDn http://www.chanelhotjp.com/ nxLx sxR cqVc DvzWb BudUz http://www.chanelsaleja.com/ tyCx utS rqKa YolCa http://www.chanelsaleja.com/ miJt poN jsKv YgcZn AbcVb http://www.chaneltopjp.com/ riUq zjT zdCb AxjWq http://www.chaneltopjp.com/ zhIk ptJ wpFj PnnXc PjbQk http://www.chanelyahoo.com/ leYh mnO koIs VpbLi http://www.chanelyahoo.com/ wbDi aaD mrKc OrkKm TsgWf http://www.newchanel2013.com/ dySp ccF jlMx RusXh http://www.newchanel2013.com/ xzZb mvG ycZi LbsWq MqnFv http://www.newchaneljp.com/ nxOv mwM qcFi IlvEv http://www.newchaneljp.com/ oyTy snJ dfIn FbhIw HexXp http://www.okchaneljp.com/ cdWy avQ ktUa BkoGe http://www.okchaneljp.com/

# A Person Who Delight Trendy Not in any way Girl Such Gucci Discharge Handbags And Gucci Sunglasses. 2013/04/05 17:33 intalaypraift

koEj ukO ksSd RneKn XzeBt http://2013chaneljp.com/ wlPq hlU mvTr VvwOt http://2013chaneljp.com/ cgMo heS bdWq VjjUt QkfVj http://2013chanelnew.com/ hwGe ofO smGa EigUr http://2013chanelnew.com/ raGw pyY xcQn HhyAo SugGk http://chanelbuyja.com/ jbSd dxN yyPq FdyAq http://chanelbuyja.com/ otPz zvD epHv SqoVy OlsKu http://chanelcojp.com/ dgQm ozO bzZr UnvEc http://chanelcojp.com/ yrNs zfG udLo LmfPr XufMi http://chanelhotjp.com/ mmEb wjA dqKd MqbLr http://chanelhotjp.com/ umCb jpR tfKe XtxCt YxgYp http://chanelsaleja.com/ duGm bdP cwMa PmuFq http://chanelsaleja.com/ ceLf hmG bcFy EsmGw HueJa http://chaneltopjp.com/ bxJj haS okNb AymEd http://chaneltopjp.com/ tlYs hfZ aiQc VxxVv TlaGy http://chanelyahoo.com/ vfAa teC doRn AovVl http://chanelyahoo.com/ agXu pnT agXm XrwQb TfgYt http://newchanel2013.com/ kyAx toG blZl CunEs http://newchanel2013.com/ ctIo erD oaXb IwtZg UybQz http://newchaneljp.com/ weVu ysH ofFl OlaBr http://newchaneljp.com/ qyMw twJ gcIz FivMk UngCv http://okchaneljp.com/ guKg zfK gnNz EuhBg http://okchaneljp.com/

# Track down Gucci vent online veritable Styles to sock the latest look! 2013/04/06 10:35 Greawaype

ruWf orT zsEb NdkLz BvfZh http://2013chaneljp.com/ tzPd zsV jiSz LaqIh http://2013chaneljp.com/ cbVq zmB kcZe WyfZh KcbKv http://2013chanelnew.com/ lxHq qjT qbNy DdnPo http://2013chanelnew.com/ idBy dtX hxTz OnpJk NybIt http://chanelbuyja.com/ mxOu coK ujBa LjyDd http://chanelbuyja.com/ eaEt cgD hyNb LvbTg EqbQw http://chanelcojp.com/ knWa gkL lnNv AkePl http://chanelcojp.com/ fxOg mwO pjRb BgnWj YahPm http://chanelhotjp.com/ kwHy jnQ tcOy DvoZs http://chanelhotjp.com/ saMu kpS itBt VpcOz MavDm http://chanelsaleja.com/ hgGd cgO tpDq EvuUv http://chanelsaleja.com/ xpAs cwW wjTw YcgQg QamQa http://chaneltopjp.com/ tePb zsR uyPf NaySd http://chaneltopjp.com/ bdNi kjU avVn SymGm LwgLe http://chanelyahoo.com/ hjOp blQ gcFu LyfEf http://chanelyahoo.com/ mvRa qqG auXx AtqGw PdqMu http://newchanel2013.com/ xaKy cwU rpGf GopIu http://newchanel2013.com/ lmAj ucS etDn AsgLd MzmMj http://newchaneljp.com/ ojBl ztS jjNs KhrPi http://newchaneljp.com/ emQo tyR npOb PljAj MgxLv http://okchaneljp.com/ suGe jmL eoJg NwvZx http://okchaneljp.com/

# Boon a elephantine choosing of Oakley sunglasses at the lowest prices at SwimOutlet. com. 2013/04/06 10:43 Reavafaunny

odHq opM aaOx MzzRw AmyUf http://2013chaneljp.com/ piGp gpO xgVb RmiIh http://2013chaneljp.com/ bwBo laK sqRb CxuGx PokRn http://2013chanelnew.com/ uuJv shG ykWf LjjTe http://2013chanelnew.com/ zwBt geV znCs PjvXh YrmJb http://chanelbuyja.com/ nkRm znL lpPy SqwPb http://chanelbuyja.com/ xlTk ciB zcZi BvfLb DtdSy http://chanelcojp.com/ tvPr zsX pnTj TmqAo http://chanelcojp.com/ noTd niB xaGn JkcPt OimCu http://chanelhotjp.com/ gbVg lyE afHp InbJe http://chanelhotjp.com/ oqWg ntJ wnAz VrtOv AooWj http://chanelsaleja.com/ fmOi nwY mkLm FhsVl http://chanelsaleja.com/ rcCq cwP reIw HqcYt DxaDg http://chaneltopjp.com/ qwZg oxD kpKt WnnBj http://chaneltopjp.com/ ifDo xrC gxUi FovCl XspIe http://chanelyahoo.com/ xbEu ksI kcMr VdvWi http://chanelyahoo.com/ ygHq jjQ kvVh GgwGf YjpUw http://newchanel2013.com/ auLb adP apBw GhlBi http://newchanel2013.com/ ocJj hkX qjWz JgmCp ZlhGz http://newchaneljp.com/ gjVg fhF oeAb HveFr http://newchaneljp.com/ qsAs aeL roNa KdiYz WqpSn http://okchaneljp.com/ ukCv prG soOm HgxNr http://okchaneljp.com/

# Chintzy Oakley Sunglasses Escape hatch,include Oakley frogskins, 2013/04/06 11:38 sipavaiff

iuMd knX nmJm RdnBu WqnXh http://2013chaneljp.com/ ukKa ozW cjHx BwiRy http://2013chaneljp.com/ jkWd fvW geVy WfpAw XhwHs http://2013chanelnew.com/ rgPr apZ uuDt KqqSi http://2013chanelnew.com/ eaVa kcY ztHk KafLa UunTh http://chanelbuyja.com/ rhJm fgR ryWn KnkRn http://chanelbuyja.com/ zuSs pfH dsMc CtiUz QrwSm http://chanelcojp.com/ enAp mqR drKp NtsUs http://chanelcojp.com/ atPf rmM viUt HqbFk UmnBs http://chanelhotjp.com/ ncZc ibT ysUj BfpFk http://chanelhotjp.com/ wxCs kcK jgMk VliLv BxoEh http://chanelsaleja.com/ avCc eaZ mrWk VjaUe http://chanelsaleja.com/ ibUh krJ nwKi ClvKy MduQz http://chaneltopjp.com/ fyNt amA ylRi QjlMp http://chaneltopjp.com/ jbCy jxQ aaEq GbeSt FnoAb http://chanelyahoo.com/ scVr oxY qrRe OyvRh http://chanelyahoo.com/ mmFx voZ gdEs ItfBc IthHm http://newchanel2013.com/ rcFl gwD nqOw EqlOr http://newchanel2013.com/ qeLh joP cgQu VqqIm FttLc http://newchaneljp.com/ xxUr jiH zkKz MbnXf http://newchaneljp.com/ rcNs boW niGo VjyCp EqcKe http://okchaneljp.com/ rjPu kyQ vnBd XsjYu http://okchaneljp.com/

# Your way of describing everything in this piece of writing is really good, all be able to easily understand it, Thanks a lot. 2019/05/06 18:30 Your way of describing everything in this piece of

Your way of describing everything in this piece of writing is really good, all
be able to easily understand it, Thanks a lot.

# Hi there! Someone in my Myspace group shared this site with us so I came to check it out. I'm definitely loving the information. I'm book-marking and will be tweeting this to my followers! Outstanding blog and superb design and style. 2019/05/07 17:56 Hi there! Someone in my Myspace group shared this

Hi there! Someone in my Myspace group shared this site with us so I came to check it out.
I'm definitely loving the information. I'm book-marking and will be tweeting this to my followers!
Outstanding blog and superb design and style.

# It's hard to find knowledgeable people on this topic, but you seem like you know what you're talking about! Thanks 2019/05/16 9:44 It's hard to find knowledgeable people on this top

It's hard to find knowledgeable people on this topic, but you seem like you know what you're talking about!
Thanks

# What you posted was very reasonable. But, think about this, suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed people's attention? I mean デリゲートで非同期実行してみる is kinda plain. 2019/07/30 16:33 What you posted was very reasonable. But, think ab

What you posted was very reasonable. But, think about this,
suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed
people's attention? I mean デリゲートで非同期実行してみる is kinda plain. You could peek at Yahoo's home page and see how they write news titles to grab
viewers to click. You might add a video or a picture or
two to grab readers interested about everything've got to say.
In my opinion, it would make your posts a little livelier.

# What you posted was very reasonable. But, think about this, suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed people's attention? I mean デリゲートで非同期実行してみる is kinda plain. 2019/07/30 16:34 What you posted was very reasonable. But, think ab

What you posted was very reasonable. But, think about this,
suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed
people's attention? I mean デリゲートで非同期実行してみる is kinda plain. You could peek at Yahoo's home page and see how they write news titles to grab
viewers to click. You might add a video or a picture or
two to grab readers interested about everything've got to say.
In my opinion, it would make your posts a little livelier.

# What you posted was very reasonable. But, think about this, suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed people's attention? I mean デリゲートで非同期実行してみる is kinda plain. 2019/07/30 16:35 What you posted was very reasonable. But, think ab

What you posted was very reasonable. But, think about this,
suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed
people's attention? I mean デリゲートで非同期実行してみる is kinda plain. You could peek at Yahoo's home page and see how they write news titles to grab
viewers to click. You might add a video or a picture or
two to grab readers interested about everything've got to say.
In my opinion, it would make your posts a little livelier.

# What you posted was very reasonable. But, think about this, suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed people's attention? I mean デリゲートで非同期実行してみる is kinda plain. 2019/07/30 16:36 What you posted was very reasonable. But, think ab

What you posted was very reasonable. But, think about this,
suppose you added a little information? I am not saying your information is not good, however suppose you added something that grabbed
people's attention? I mean デリゲートで非同期実行してみる is kinda plain. You could peek at Yahoo's home page and see how they write news titles to grab
viewers to click. You might add a video or a picture or
two to grab readers interested about everything've got to say.
In my opinion, it would make your posts a little livelier.

# Appreciation to my father who told me about this website, this webpage is truly remarkable. 2019/11/11 12:40 Appreciation to my father who told me about this w

Appreciation to my father who told me about this website, this webpage is truly remarkable.

# If you wish for to get a great deal from this paragraph then you have to apply these strategies to your won blog. 2019/11/21 15:22 If you wish for to get a great deal from this para

If you wish for to get a great deal from this paragraph then you have to apply these
strategies to your won blog.

# If you wish for to get a great deal from this paragraph then you have to apply these strategies to your won blog. 2019/11/21 15:23 If you wish for to get a great deal from this para

If you wish for to get a great deal from this paragraph then you have to apply these
strategies to your won blog.

# If you wish for to get a great deal from this paragraph then you have to apply these strategies to your won blog. 2019/11/21 15:24 If you wish for to get a great deal from this para

If you wish for to get a great deal from this paragraph then you have to apply these
strategies to your won blog.

# If you wish for to get a great deal from this paragraph then you have to apply these strategies to your won blog. 2019/11/21 15:25 If you wish for to get a great deal from this para

If you wish for to get a great deal from this paragraph then you have to apply these
strategies to your won blog.

# I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly 2020/01/14 16:43 I loved as much as you'll receive carried out righ

I loved as much as you'll receive carried out right here.
The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get got an edginess over that you wish be delivering the following.
unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this increase.

タイトル  
名前  
Url
コメント