public async Task addWord(Word word) { List <string> wordList = new List <string>(); try { using (StreamReader reader = File.OpenText(FileName)) { string line; while ((line = await reader.ReadLineAsync()) != null) { // no use in adding a word that already exists if (line == word.Content) { return; } wordList.Add(line); } } wordList.Add(word.Content); File.WriteAllLines(FileName, wordList.OrderBy(x => x).ToArray()); } catch (FileNotFoundException e) { messenger.Debug(e.Message); messenger.Error("Het bestand is niet gevonden."); } catch (IOException e) { messenger.Debug(e.Message); messenger.Error("Er is is misgegaan bij het lezen van het woord bestand."); } }