阻止后台任务更新 LiveTile
我真的需要你的帮助,因为我有一个令人沮丧的问题。我正在定期代理 (OnInvoke) 中下载数据。工作正常,但每天晚上我下载数据的网站都没有数据可供下载。如果发生这种情况,我希望活动磁贴保持原样(而不是空)并包含当前数据,并且不更新。然后一两个小时后,当有数据需要下载和解析时,更新应该继续。
我已经尝试过这个,但是当调用 NotifyComplete 时,代码仍然会被执行。 NotifyComplete 不是应该停止其余代码的执行吗?
MatchCollection matchesMyData = rxMyData.Matches(strHTML);
foreach (Match matchMyData in matchesMyData)
{
GroupCollection groupsMyData = matchMyData.Groups;
//Code for handling downloaded data
}
if (matchesMyData.Count < 1)
{
ShellToast toast = new ShellToast();
toast.Title = "No update: ";
toast.Content = "Webservice returned no data";
toast.Show();
NotifyComplete();
}
我还尝试了以下代码,但这停止了我的后台任务,我必须再次启动我的应用程序才能重新启用它。为什么?
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("TileID=2"));
if (TileToFind != null && intCount > 0)
{
//Update the live tile
}
因此,当没有解析数据时,图块应保持原样,一两个小时后,当数据下载完毕时,随着图块的更新,一切都应恢复正常。
请帮忙,因为这现在是一个阻碍。提前致谢。
I really need your help since I have a frustrating problem. I'm downloading data in my periodic agent (OnInvoke). Works fine but every night the web site I download data from has no data to download. If that happens I want the live tile to remain as it is (instead of beeing empty) with the current data and not get updated. Then one or two hours later when there is data to download and parse the update should continue.
I have tried this but when NotifyComplete is called the the code after still gets executed. Isn't NotifyComplete supposed to stop the rest of the code to be executed?
MatchCollection matchesMyData = rxMyData.Matches(strHTML);
foreach (Match matchMyData in matchesMyData)
{
GroupCollection groupsMyData = matchMyData.Groups;
//Code for handling downloaded data
}
if (matchesMyData.Count < 1)
{
ShellToast toast = new ShellToast();
toast.Title = "No update: ";
toast.Content = "Webservice returned no data";
toast.Show();
NotifyComplete();
}
I also tried the following peice of code but that stopped my background task and I had to start my app again to re-enable it. Why?
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("TileID=2"));
if (TileToFind != null && intCount > 0)
{
//Update the live tile
}
So, when no data gets parsed the tile should remain as it is and an hour or two later when data gets downloaded everything should be back to normal with thetile beeing updated.
Please help, since this is a show stopper right now. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用 NotifyComplete() 不会在方法调用执行后停止代码,它只是让操作系统知道您已完成。操作系统应该中止线程,但可能还有时间运行更多几行代码(文档不清楚调用 NotifyComplete 的线程是否会立即中止)。
如果您在调用 NotifyComplete 之后添加返回语句,则不应更新磁贴。
Calling NotifyComplete() will not stop the code after the method call being executed, it just lets the OS know that you are finished. The OS should abort the thread but there may be time for a few more lines of code to run (the documentation isn't clear on whether the thread that calls NotifyComplete will be aborted immediately).
If you add a return statement after the call to NotifyComplete then the tile shouldn't be updated.