2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rxを使って、LocationChangedイベントを捕まえる --泣きながらC#

Last updated at Posted at 2012-08-26

副題が付いていますが、続き物になるなんてことは無いです。

LINQですよLINQ!いや、LINQはわかる。

データを流れるように扱うLINQはわかる。Rxもその発想だってのもまあ、分かる。

わかるんだけど難しい。難しいから挑戦する、そんな日曜の昼下がり。

Rxらしく1行です。

rxgps.cs
var geoWatcher = new GeoCoordinateWatcher();

Observable.FromEvent<GeoPositionChangedEventArgs<GeoCoordinate>>(geoWatcher, "PositionChanged").
ObserveOnDispatcher().
Select(ev => ev.EventArgs.Position.Location).
Take(1).
Subscribe(location => Debug.WriteLine(location.Longitude.ToString()), () => { Debug.WriteLine("completed"); geoWatcher.Stop(); });

geoWatcher.Start();

take(1) ・・・?

なんで、take(1)なん?

これ外すと、onCompletedが呼ばれない。

あれ?でも、Subscribeは呼ばれてるよ?データの処理は終わったんじゃないの??

Rx難しいねー

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?