Вопрос

I'm having some problems. Here's my code:

private async void SetCollectionForGame()
{
    maincollection = new Dictionary<string, string>();

    bool statebase = await CheckExistingBase();

    if (statebase)
    {
        //If file exists...
        basefile = await folder.GetFileAsync(basefilename);
    }
    else
    {
        //If file does not exist...
        SaveBaseFileAsync(filelink, folder, basefilename);
        basefile = await folder.GetFileAsync(basefilename);
    }
    string content = String.Empty;
    content = await FileIO.ReadTextAsync(basefile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
    //When the app first starts, I get an exception on the next line,
    //because the variable "content" is null.
    maincollection = JsonConvert.DeserializeObject<CollectionModel>(content).collection;
}

Does anybody know how to solve this? File downloading works fine, and after the download the file was created in a folder.

Это было полезно?

Решение

Based on the name, I suspect that SaveBaseFileAsync() executes some async operations. If it's true, you need to await it, i.e. call it as

await SaveBaseFileAsync(filelink, folder, basefilename);

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top