예제 #1
0
        void StartGettingFeed(Frame frame)
        {
            getWeatherReportsSource = new CancellationTokenSource();
            CancellationToken WRtoken = getWeatherReportsSource.Token;

            getTweetsSource = new CancellationTokenSource();
            CancellationToken TweetsToken = getTweetsSource.Token;

            AppDataManager.viewModel = viewModel;

            getWeatherReportsTask = new Task(async() =>
            {
                viewModel.LoadReportCache = await AppDataManager.RestoreFromLocalCacheAsync <ObservableCollection <WeatherReport> >("reports");
                while (!WRtoken.IsCancellationRequested)
                {
                    await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                    async() =>
                    {
                        viewModel.ReportsList = await FeedFetch.GetWeatherFeedAsync(AppSettingsData.GetReportQuery);
                        await AppDataManager.SaveToLocalCacheAsync <ObservableCollection <WeatherReport> >
                            (viewModel.ReportsList, AppSettingsData.reportsFileName);
                    });

                    WRtoken.WaitHandle.WaitOne(AppSettingsData.UpdatesIntervalMsec);
                }
            });

            getTweetsTask = new Task(async() =>
            {
                while (!TweetsToken.IsCancellationRequested)
                {
                    AppSettingsData.TweetsToLoad = await AppSettingsData.LoadTweets();
                    await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                    async() =>
                    {
                        viewModel.TweetList = await FeedFetch.GetTweetsAsync(AppSettingsData.TweetsToLoad);
                    });
                    TweetsToken.WaitHandle.WaitOne(AppSettingsData.UpdatesIntervalMsec);
                }
            });


            getWeatherReportsTask.Start();
            getTweetsTask.Start();
        }