2014-01-30 48 views
0

閱讀在JumpStart視頻(適用於Windows Phone 8的快速入門開發應用程序) 他們發現給我的錯誤示​​例代碼: 「異步方法的返回類型必須是void牛逼從localStorage的

的,任務或任務

這是示例代碼:

//open 
private async string loadStringAsync() 
{ 
    string theData = string.Empty; 

    //Get a reference to the local folder 
    StorageFolder localFolder = ApplicationData.Current.LocalFolder; 
    StorageFile storageFile = await localFolder.GetFileAsync("MyFile.store"); 

    //Open it and read it 
    Stream readStream = await storageFile.OpenStreamForReadAsync(); 
    using (StreamReader reader = new StreamReader(readStream)) 
    { 
    theData = await reader.ReadToEndAsync(); 
    } 
    return theData; 
} 

我想這需要一個簡單的修復,但由於我是新來的編程和評論是在那個特定的視頻停用了,我不知道如何..

+0

你讀過錯誤了嗎? http://msdn.microsoft.com/en-us/library/hh191443.aspx – SLaks

+0

感謝您的鏈接,我認爲這可能是最好的閱讀異步編程第一次確實:) – TomCB

回答

0
var a = loadStringAsync(); 

private async Task<string> loadStringAsync() 
{ 
    string theData = string.Empty; 

    //Get a reference to the local folder 
    StorageFolder localFolder = ApplicationData.Current.LocalFolder; 
    StorageFile storageFile = await localFolder.GetFileAsync("MyFile.store"); 

    //Open it and read it 
    Stream readStream = await storageFile.OpenStreamForReadAsync(); 
    using (StreamReader reader = new StreamReader(readStream)) 
    { 
     theData = await reader.ReadToEndAsync(); 
    } 
    return theData; 
}