wp8 入门到精通 定时更新瓷贴
public class ScheduledAgent : ScheduledTaskAgent
{
static ScheduledAgent()
{
Deployment.Current.Dispatcher.BeginInvoke(delegate
{
Application.Current.UnhandledException += UnhandledException;
});
}
private static void UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached)
{
Debugger.Break();
}
}
private static Mutex mut = new Mutex();
protected override void OnInvoke(ScheduledTask task)
{
System.Diagnostics.Debug.WriteLine("OnInvoke");
SetChange(task);
#if DEBUG_AGENT
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif
}
/// <summary>
/// 更新 hot
/// </summary>
/// <param name="hot"></param>
private void IsRemained(Hot hot)
{
mut.WaitOne(); // Wait until it is safe to enter
try
{
if (CCTools.Utils.Instance.GetValueOrDefault<Hot>("Hot", null) == null)
CCTools.Utils.Instance.AddOrUpdateValue<Hot>("Hot", hot);
else
{
Hot lhot = CCTools.Utils.Instance.GetValueOrDefault<Hot>("Hot", hot);
if (!hot.recommend_caption.Contains(lhot.recommend_caption))
CCTools.Utils.Instance.AddOrUpdateValue<Hot>("Hot", hot);
}
}
catch
{
}
finally
{
mut.ReleaseMutex(); // Release the Mutex.
}
}
private void SetHot(Hot hot)
{
try
{
FlipTileData TileData = new FlipTileData();
TileData.BackTitle = "信息学";
TileData.BackContent = hot.recommend_caption;
TileData.WideBackContent = hot.recommend_caption;
TileData.BackBackgroundImage = new Uri(hot.recommend_cover_pic, UriKind.Absolute);
TileData.WideBackBackgroundImage = new Uri(hot.recommend_cover_pic, UriKind.Absolute);
TileData.SmallBackgroundImage = new Uri("/Assets/Tiles/FlipCycleTileSmall.png", UriKind.Relative);
TileData.BackgroundImage = new Uri("/Assets/Tiles/FlipCycleTileMedium.png", UriKind.Relative);
TileData.WideBackgroundImage = new Uri("/Assets/Tiles/FlipCycleTileLarge.png", UriKind.Relative);
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault();
if (TileToFind != null)
TileToFind.Update(TileData);
System.Diagnostics.Debug.WriteLine("SetHot");
NotifyComplete();
}
catch
{
}
}
private void SetChange(ScheduledTask task)
{
System.Diagnostics.Debug.WriteLine("SetChange");
string apiUrl = "";
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri(apiUrl, UriKind.Absolute));
wc.DownloadStringCompleted += wc_DownloadStringCompleted;
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
IList<Hot> list = new List<Hot>();
try
{
#region MyRegion
JArray jsonArray = JArray.Parse(e.Result);
Hot status = null;
if (jsonArray != null)
{
foreach (var j in jsonArray.Children())
{
status = j.ToObject<Hot>();
list.Add(status);
}
}
#endregion
System.Diagnostics.Debug.WriteLine("组装完成");
Hot hot = list[0];
SetHot(hot);
}
catch { }
}
}
public partial class MainPage : PhoneApplicationPage
{
PeriodicTask periodicTask;
string periodicTaskName = "PeriodicAgent";
public bool agentsAreEnabled = true;
public MainPage()
{
InitializeComponent();
this.Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
StartPeriodicAgent();
}
private void StartPeriodicAgent()
{
agentsAreEnabled = true;
periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
if (periodicTask != null)
{
RemoveAgent(periodicTaskName);
}
periodicTask = new PeriodicTask(periodicTaskName);
periodicTask.Description = "This demonstrates a periodic task.";
try
{
ScheduledActionService.Add(periodicTask);
// If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if DEBUG_AGENT
ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif
}
catch (InvalidOperationException exception)
{
}
catch (SchedulerServiceException)
{
}
}
private void RemoveAgent(string name)
{
try
{
ScheduledActionService.Remove(name);
}
catch (Exception)
{
}
}
}
wp8 入门到精通 定时更新瓷贴的更多相关文章
- wp8 入门到精通 数据库更新字段(一)
public class UserInfoDB : BaseDB { public UserInfoDB() : base(@"Data Source=isostore:\MakeLove\ ...
- wp8 入门到精通 虚拟标示符 设备ID
//获得设备虚拟标示符 wp8 public string GetWindowsLiveAnonymousID() { object anid = new object(); string anony ...
- wp8 入门到精通 仿美拍评论黑白列表思路
static bool isbool = false; private void BindGameDelete() { Tile tile = new Tile(); List<Color> ...
- wp8 入门到精通 生命周期
- wp8 入门到精通 ImageCompress 图片压缩
//实例化选择器 PhotoChooserTask photoChooserTask = new PhotoChooserTask(); BitmapImage bimg; int newPixelW ...
- wp8 入门到精通 Gallery
<Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.Resources> ...
- wp8 入门到精通 MultiMsgPrompt
List<NotifyMsg> arraymsg = new List<NotifyMsg>(); List<NotifyInfo> ArrayNotifyInfo ...
- wp8 入门到精通 启动系统分享照片任务
PhotoChooserTask photoChooserTask = new PhotoChooserTask(); photoChooserTask.Completed += photoChoos ...
- wp8 入门到精通 Utilities类 本地存储+异步
public class CCSetting { public async static void AddOrUpdateValue<T>(string key, T value) { t ...
随机推荐
- Python类的特点 (2) :类属性与实例属性的关系
测试代码: #encoding:utf-8 class Parent(object): x=1 #x是Parent类的属性(字段) ls=[1,2] #ls是一个列表,也是Parent类的属性(字段) ...
- Vim保存只读模式下的修改
用 vim 打开没有写权限的文件而忘记用 sudo 时,文件变成 read-only这时候用 :w!, SHIFT+ZZ,或者 qw! 都无法保存 :w !sudo tee % :w : Write ...
- [20160730]while 条件的死循环和正常循环对比
正常循环 import java.io.*; import java.util.*; public class MyPrintStreamTest3{ public static void main( ...
- Binary Tree Non-recursive Traversal
Preorder: public static void BSTPreorderTraverse(Node node) { if (node == null) { return; } Stack< ...
- poj 2403
http://poj.org/problem?id=2403 题意:就是给你m个单词,以及n段对话.每一个单词都有所对应的价值.求对话中的价值总和 题解:很简单,就是用单词和价值对应起来,然后再寻找就 ...
- struts2 action 3中书写方式
1.pojo类 简单的javabean 类 需要有 public String execute(){return null;} 2.实现 Action 借口 重写 execute 3.继承 Ac ...
- redis与memcache区别总结
2015年9月2日 14:04:19 总会被问到两者的区别, 在这里总结下: redis 有内置的多种数据结构, list(可用于实现小型队列), hash, set, zset...; memcac ...
- 和我一起学python,初识python (life is short ,we need python)
作者:tobecrazy 出处:http://www.cnblogs.com/tobecrazy 欢迎转载,转载请注明出处.thank you! 由于项目需要(并非因为life is short), ...
- Python~if,while,for~顺序,判断,循环
if A: for -in : while x: if A:elif:else: 不能直接用int进行迭代,而必须加个range. range(len(L)) int ob ...
- 服务器×××上的MSDTC不可用解决办法
MSDTC(分布式交易协调器),协调跨多个数据库.消息队列.文件系统等资源管理器的事务.该服务的进程名为Msdtc.exe,该进程调用系统Microsoft Personal Web Server和M ...