void CheckWords() { // We cache words to prevent unneccessary lookups. if (m_WordCache == WordChecker.GetWord(m_PlayerCached.selectedTiles)) { return; } m_WordCache = WordChecker.GetWord(m_PlayerCached.selectedTiles); // Clear any old results. m_ViewModel.player.orderedResult.hasValue = false; m_ViewModel.player.orderedResult.hasValue = false; // If any word check threads are running, abort them here, to prevent any race conditions. if (WordChecker.taskCount > 0) { WordChecker.AbortAllTasks(); } // Two word checks are performed - one is an ordered word check, and one checks word permutations. // Different callbacks are used for each one. // The SetResuable method lets the task object get used again and reduces garbage allocation. WordChecker.CheckWordAsync(m_PlayerCached.selectedTiles, OnCheckWordOrdered).SetReusable(); WordChecker.CheckWordAsync(m_PlayerCached.selectedTiles, OnCheckWordPermute, false).SetReusable(); }