Windows Phone 8和Surface pro 2 OpenStreamForWriteAsync会阻止该应用

时间:2014-05-09 17:45:23

标签: c# .net windows windows-phone-8 filestream

我正在开发一个针对Windows Phone和Surface pro 2应用的项目,我正在寻找从.txt文件中读取文本。

我是Windows应用程序开发的新手,我接管了另一个人的项目。

我暂时没有改变他的代码,但有些事情我不明白,主要的问题是,当我使用应用程序时,当我调用方法时,这个被阻止了> OpenStreamForWriteAsync()

以下是代码:

public async void FillIn()
{
    Stream stream1 = null;
    StorageFolder storageFolder = KnownFolders.DocumentsLibrary; // Gets Documents library
    //The following structure code in comment is from me, is it necessary to 
    //do all these verification or "StorageFolder storageFolder =
    //KnownFolders.DocumentsLibrary;" is enough ?  
    //try
    //{
    //    folder = await KnownFolders.DocumentsLibrary.GetFolderAsync(AppFolderName);
    //}
    //catch (Exception)
    //{
    //    // Folder does not exist, but we cannot await in a catch block, so we can not create it here.
    //}

    //if (folder == null)
    //{
    //    folder = await KnownFolders.DocumentsLibrary.CreateFolderAsync(AppFolderName, CreationCollisionOption.OpenIfExists);
    //}

    // Test if the file exist
    StorageFile report1 = null;
    try
    {
        report1 = await storageFolder.GetFileAsync("report_final.txt"); // Take the .txt file.
    }
    catch { }

    if (report1 == null)
    {
        // Could not find file
    }

    // PROBLEM IS HERE
    stream1 = await report1.OpenStreamForWriteAsync(); // the app is blocked at this line

    using (StreamReader sr1 = new StreamReader(stream1))
    {
        Texte = sr1.ReadToEnd();
        sr1.Dispose(); // the guy before me use this but when we use "using" 
        //isn't it suppose to call "Dispose" at the end automatically ??
    }
}

感谢您的帮助,如果您不了解某些内容,请随时向我提出更多信息。

0 个答案:

没有答案