建体彩网|中彩网双色球连号|
?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

亞博娛樂國際最新版本:深入學習Windows Phone7(一. Reactive Extension)

?

Reactive Extension for .Net framework

.Net反映性框架,在之前的.net框架中就已經有了,沒想到也被利用到Windows phone7中來了。

法度榜樣員為指定異步操作指定回調,或事故處置懲罰法度榜樣的時刻應用反映性編程。在異步操作完成或者事故觸發的時刻,就會調用措施并作為對該事故的反映。在這個模型中,數據流、異步哀求、事故都可以做為可察看序列,并且接管異步消息,并經由過程LINQ來合成這些序列。

不過在Phone7中,這個框架只有一部分有用,主要用在:filtering events、composing multiple asynchronous web service requests、emulating data streams.

對付今朝來說,在模擬器上沒有法子測試Accelerometer和Location的API,便是由于得不到數據亞博娛樂國際最新版本。現在可以使用這個框架來實現數據模擬了。

模擬Accelerometer數據:

Thread thread = new Thread(StartAccelerometerEmulation);

thread.Start();

am = new Accelerometer();

var aro = Observable.FromEventAccelerometerReadingEventArgs>(

eh => am.ReadingChanged += eh,

eh => am.ReadingChanged -= eh);

try

{

am.Start();

}

catch (AccelerometerFailedException ae)

{

}

void InvokeAccelerometerReadingChanged(Vector3 data)

{

Deployment.Current.Dispatcher.BeginInvoke(() => AccelerometerReadingChanged(data));

}

void AccelerometerReadingChanged(Vector3 data)

{

this.textBlock1.Text = "x: " + data.X.ToString("0.00");

this.textBlock2.Text = " y: " + data.Y.ToString("0.00");

this.textBlock3.Text = " z: " + data.Z.ToString("0.00");

}

private void StartAccelerometerEmulation()

{

var emulationDataAsObservable = EmulateAccelerometerReading().ToObservable();

em亞博娛樂國際最新版本ulationDataAsObservable.Subscribe(args => InvokeAccelerometerReadingChanged(args));

}

static IEnumerableVector3> EmulateAccelerometerReading()

{

Random random = new Random();

for (double theta = 0; ; theta += .1)

{

Vector3 reading = new Vector3((float)Math.Sin(theta), (float)Math.Cos(theta * 1.1), (float)Math.Sin(theta * .7));

reading.Normalize();

if (random.NextDouble() > .95)

{

reading = new Vector3((float)(random.NextDouble() * 3.0 - 1.5),

(float)(random.NextDouble() * 3.0 - 1.5),

(float)(random.NextDouble() * 3.0 - 1.5));

}

yield return reading;

Thread.Sleep(200);

}

}

模擬Location數據:

Thread t = new Thread(StartLocationEmulation);

t.Start();

watcher = new Ge亞博娛樂國際最新版本oCoordinateWatcher(GeoPositionAccuracy.Default);

watcher.MovementThreshold = 35;

var gcwo = Observable.FromEventGeoPositionChangedEventArgsGeoCoordinate>>(

eh =>watcher.PositionChanged +=eh,

eh =>watcher.PositionChanged -=eh);

watcher.Start();

private void StartLocationEmulation()

{

var position = EmulatePositionChangedEvents().ToObservable();

position.Subscribe(ev => wait_PositionChanged(null, ev));

}

stati亞博娛樂國際最新版本c IEnumerableGeoPositionChangedEventArgsGeoCoordinate>> EmulatePositionChangedEvents()

{

Random random = new Random();

while (true)

{

double latitude = (random.NextDouble() * 180.0) - 90.0; // latitude is between -90 and 90

double longitude = (random.NextDouble() * 360.0) - 180.0; // longitude is between -180 and 180

yield return new GeoPositionChangedEventArgsGeoCoordinate>(

new GeoPositionGeoCoor亞博娛樂國際最新版本dinate>(DateTimeOffset.Now, new GeoCoordinate(latitude, longitude)));

Thread.Sleep(random.Next(2000));

}

}

private void wait_PositionChanged(object sender, GeoPositionChangedEventArgsGeoCoordinate> e)

{

Deployment.Current.Dispatcher.BeginInvoke(()=>MyPositionChanged(e));

}

private void MyPositionChanged(GeoPositionChangedEventArgsGeoCoordinate> e)

{

this.textBlock1.Text = "Time: " + e.Position.Timestamp. ToString("yyyy-MM-dd hh:mm:ss");

this.textBlock2.Text = "Latitude: " + e.Position.Location.Latitude.ToString("0.00");

this.textBlock3.Text = "Longitude: " + e.Position.Location.Longitude.ToString("0.00");

}

轉自:http://www.cnblogs.com/randylee/archive/2010/09/01/1814654.html

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

建体彩网
北京快3万能两码走势 美人捕鱼下载 华夏银行股票行情 球探网蓝球 188足球比分直播 广西快乐十分开将结果直播 内蒙古十一选五走势图 体彩20选5怎么中奖表 365小游戏试玩 快乐12技巧视频教程