0

我有一个包含许多页面的项目。无论我的应用程序的情况如何,我都想定期将信息导入我的数据库。

我试图将我的代码放在 App.xaml.cs 中,但它只保存一次数据(我把它放在启动中并在构造函数中尝试。我的方法是获取设备 ID 的位置,就像

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    Location loc = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);

    //Send Data to Database
    dclient.CreateUserLocationCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(dclient_CreateUserLocationCompleted);
    dclient.CreateUserLocationAsync(1, loc.Latitude, loc.Longitude);
} 

并且我的观察者位置更改在构造函数内部。

if (watcher == null)
{
    watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High)
}

MovementThreshold = getSelectedDeviceLocationFrequencyFromInternalFolder();

watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
watcher.Start();

并在 App.xaml.cs 中全局定义

如何在程序运行时始终定期运行它?还有什么办法吗?谢谢(总而言之,我想定期将位置数据插入我的数据库。)

4

1 回答 1

0

您将需要在应用程序启动时启动一个线程,该线程在它想要的任何时间休眠(或从应用程序的信号唤醒 - 当收到新值时)并将数据写入其中的数据存储。

于 2012-05-10T15:28:36.460 回答