在我的Windows Phone 8 App中,我需要在凌晨2点触发API。但是,据我在Windows Phone 8中分析,计划任务将仅每30分钟触发一次,并且无法设置计时器。任何人都可以建议我如何在Windows Phone 8中实现这一点。 请查看我目前为止尝试过的代码。
预定的任务OnInvoke方法。
protected async override void OnInvoke(ScheduledTask task)
{
GeoLocationService gs = GeoLocationService.InstanceCreation();
repository = new HeartBeatRepository();
HeartBeatModel _hbmodel = new HeartBeatModel();
_hbmodel.MBeatName = "Heartbeat_";
_hbmodel.MDataRoaming = "";
_hbmodel.MDeviceID = "";
_hbmodel.MFullName = "";
_hbmodel.MLatitude = await gs.getlatitude();
_hbmodel.MLongitude =await gs.getlongitude();
_hbmodel.MTimeStamp = "";
string userID = Convert.ToString(StateManagement.Current.GetValue("UserID"));
if (userID.Length != 0)
{
await repository.PutHearBeat(userID, _hbmodel);
}
var curtime = DateTime.Now;
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromMinutes(60 - curtime.Minute));
NotifyComplete();
}
激活API的类文件,我在这里检查时间是否为2.00 A.M。
public class HeartBeatRepository
{
public async Task<string> PutHearBeat(string userId, HeartBeatModel _heartbeatmodel)
{
if (DateTime.Now.ToString("hh:mm:ss tt").Equals((DateTime.ParseExact("2.00", "hh:mm:ss tt", CultureInfo.CurrentCulture).ToString())))
{
var serviceProvider = new ServiceProvider(new HeartBeatHttpHandler(string.Format(Services.Services.PutHeartBeatData, userId)));
var assetDetails = (string)await serviceProvider.PutData(_heartbeatmodel);
return assetDetails;
}
return null;
}
}