えムナウ Blog

えムナウ の なすがまま

目次

Blog 利用状況

ニュース


follow mnow at http://twitter.com


えムナウのプログラミングのページ

INETAJ

書庫

日記カテゴリ

ギャラリ

Reactive Extensions の非同期

Reactive Extensions の非同期 については今まで簡単に書こうというつもりがなく動作検証でいっぱいいっぱいだったため短く1行出かけるパターンをお見せしておきたいと思う。
下のコードはDebug.WriteLineを追加してあるので行数は増えているが抜けば1行でも書ける。

Func<int, int> nullFunc = z => {

  System.Diagnostics.Debug.WriteLine("FromAsyncPattern start"); Thread.Sleep(1000);
  System.Diagnostics.Debug.WriteLine("FromAsyncPattern end"); return z + 1; };


var
fromAsyncPattern = Observable.FromAsyncPattern<int,int>(nullFunc.BeginInvoke, nullFunc.EndInvoke);

var fromAsyncDispose = fromAsyncPattern(1).Subscribe(z =>

        System.Diagnostics.Debug.WriteLine("FromAsyncPattern result {0}", z)

    );

System.Diagnostics.Debug.WriteLine("FromAsyncPattern");

FromAsyncPattern start
FromAsyncPattern
FromAsyncPattern end
FromAsyncPattern result 2

投稿日時 : 2010年7月28日 2:11

コメントを追加

No comments posted yet.
タイトル
名前
URL
コメント