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 ...
随机推荐
- phpcms的评论改为留言板研究
研究背景: phpcms里面默认是没有留言板的,之前我的博客里发过一个二次开发简介,里面有一个简单的留言板,包含前台提供表单,后台留言审核等功能,但是不提供用户登录等操作. 研究思路: phpcms里 ...
- discuz论坛移植修改数据库配置
从其他地方拷贝的discuz源码,可能需要修改数据库配置 分别打开discuz目录下面以下三个文件 discuzRoot/uc_server/data/config.inc.phpdiscuzRoot ...
- 不懂点CAP理论,你好意思说你是做分布式的吗?
- Java 抽象类与oop三大特征
面向对象主要有三大特性:继承和多态.封装. 一.抽象类 在了解抽象类之前,先来了解一下抽象方法.抽象方法是一种特殊的方法:它只有声明,而没有具体的实现.抽象方法的声明格式为: abstract voi ...
- 4.nodejs权威指南--TCP和UDP
1. TCP和UDP 1.1 TCP服务端 var net = require('net'); var server = net.createServer(); server.on('connecti ...
- gcc-5.4.0 static dwarf2 compile
------------------------------------------------------------------------------- 又开始折腾了, 静态编译 gcc-5.4 ...
- codeforces 496A. Minimum Difficulty 解题报告
题目链接:http://codeforces.com/contest/496/problem/A 题目意思:给出有 n 个数的序列,然后通过删除除了第一个数和最后一个数的任意一个位置的数,求出删除这个 ...
- 20145213《Java程序设计》第五周学习总结
20145213<Java程序设计>第五周学习总结 教材学习内容总结 "素衣莫起风尘叹,犹及清明可到家."每每念此,不得不心疼自己.古人清明长假都进城耍了,还担心自己清 ...
- 【XLL API 函数】xlCoerce
将 XLOPER/XLOPER12 转换为另一种类型,或是查询表格中的单元格值. 函数原型 Excel12(xlCoerce, LPXLOPER12 pxRes, 2, LPXLOPER12 pxSo ...
- [Java 基础] 使用java.util.zip包压缩和解压缩文件
reference : http://www.open-open.com/lib/view/open1381641653833.html Java API中的import java.util.zip ...