在我的WP7应用程序中,我正在为实时图块生成图像并保存在隔离存储中.
然后它可用于我的周期性任务来更新实时图块,并且在这方面一切正常用于周期性任务.
然后它可用于我的周期性任务来更新实时图块,并且在这方面一切正常用于周期性任务.
当我创建实时图块图像时,我的问题是我的前景WP7应用程序中的点我也更新了实时图块(因为我知道某些内容已经改变,所以为什么要等待周期性任务).但是当在这里发生实时图块更新时,似乎找不到新创建的文件,因此呈现没有位图的实时图块.
就相关代码而言
创建文件
var source = new BitmapImage(new Uri("Images/Tiles/Class TiMetable with T.png",UriKind.Relative)); source.CreateOptions = BitmapCreateOptions.None; source.ImageOpened += (sender,e) => // This is important. The image can't be rendered before it's loaded. { // Create our image as a control,so it can be rendered to the WriteableBitmap. var newImage = new Image(); newImage.Source = source; newImage.Width = 173; newImage.Height = 173; // Define the filename for our tile. Take note that a tile image *must* be saved in /Shared/ShellContent // or otherwise it won't display. var tileImage = string.Format("/Shared/ShellContent/{0}.jpg",Event.UniqueId); // Define the path to the isolatedstorage,so we can load our generated tile from there. var isoStoreTileImage = string.Format("isostore:{0}",tileImage);
和实际保存本身
// Create a stream to store our file in. var stream = store.CreateFile(tileImage); // Invalidate the bitmap to make it actually render. bitmap.Invalidate(); // Save it to our stream. bitmap.SaveJpeg(stream,173,100); // Close the stream,and by that saving the file to the ISF. stream.Close();
以及实际检索图像并更新实时图块的代码(并且在周期性任务中工作但不在应用程序本身中工作
string imageString = "isostore:/Shared/ShellContent/" + nextEvent.UniqueId + ".jpg"; ShellTile defaultTile2 = ShellTile.ActiveTiles.First(); defaultTile2.Update(new StandardTileData { Title = nextTime,BackgroundImage = (new Uri(imageString,UriKind.Absolute)),});
只是不确定我这里是否做了一些根本错误的事情?我正在考虑将生成的图像与其对象一起存储在数据库中.而且,我确实有一个可管理的文件数量.我没有产生数以百计的东西.
解决方法
嘿,代码看起来很熟悉;-)除此之外,您发布的代码中没有任何内容可以确定问题.
我的猜测是你在定期任务的早期调用NotifyComplete().为此,我建议您使用任务并行库来解决问题.
我今天早上写了一篇关于它的文章:How To: Live Tile with Scheduled Agent
关键部分是使用Task.ContinueWith确保在完成渲染背景图像后首先调用NotifyComplete(),并将其保存到隔离存储中.