在解除WP8应用程序后

在解除WP8应用程序后

本文介绍了在解除WP8应用程序后,UploadAsync不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序尝试将文件保存到SkyDrive即将关闭。


当我的应用程序在前台运行时,我的UploadAsync调用没有问题。


为了在我的应用程序关闭时将文件保存到SkyDrive,我像这样覆盖了OnBack按钮:

 protected override void OnBackKeyPress(CancelEventArgs e)
{
SaveSkydriveData();
base.OnBackKeyPress(e);
}





SaveSkydriveData看起来像这样:


公共异步任务SaveSkydriveData()
{
IsolatedStorageFile商店= IsolatedStorageFile.GetUserStoreForApplication();
FileStream stream = store.OpenFile(" MyData.txt",FileMode.Create);
StreamWriter writer = new StreamWriter(stream);
writer.Write(" blah");
writer.Close();
stream.Close();

FileStream readstream = store.OpenFile(" MyData.txt",FileMode.Open);
readstream.Position = 0;
var result = await client.UploadAsync(" me / skydrive"," MyData.txt",readstream,OverwriteOption.Overwrite);
readstream.Close();
}

为什么这不起作用?如果在我的应用程序仍在运行时调用,SaveSkydriveData()将按预期工作。但它似乎不适用于上述情况。



谢谢!


解决方案


Hi, I have an app that tries to save a file to SkyDrive when it is just about the be closed.

While my app is running in the foreground, my UploadAsync call works without a problem.

In order to save the file to SkyDrive as my app closes, I overrode the OnBack button like so:

protected override void OnBackKeyPress(CancelEventArgs e)
        {
            SaveSkydriveData();
            base.OnBackKeyPress(e);
        }


And SaveSkydriveData looks something like this:

public async Task SaveSkydriveData()
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
            FileStream stream = store.OpenFile("MyData.txt", FileMode.Create);
            StreamWriter writer = new StreamWriter(stream);
            writer.Write("blah");
            writer.Close();
            stream.Close();

            FileStream readstream = store.OpenFile("MyData.txt", FileMode.Open);
            readstream.Position = 0;
            var result = await client.UploadAsync("me/skydrive", "MyData.txt", readstream, OverwriteOption.Overwrite);
            readstream.Close();
        }

Why doesn't this work? SaveSkydriveData() works as expected if called while my app is still running. But it doesn't seem to work in the above scenario.

Thanks!

解决方案


这篇关于在解除WP8应用程序后,UploadAsync不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:45