public void CanRunAsyncMethodsAndWait() { string taskId = Guid.NewGuid().ToString("N"); //_cacheClient.Set(taskId, 0); string id = "51cf1b597841550f1c44b539"; var tasks = new[] { _errorStackRepository.RemoveAllByProjectIdAsync(id), _errorRepository.RemoveAllByProjectIdAsync(id), _dayStackStats.RemoveAllByProjectIdAsync(id), _monthStackStats.RemoveAllByProjectIdAsync(id), _dayProjectStats.RemoveAllByProjectIdAsync(id), _monthProjectStats.RemoveAllByProjectIdAsync(id) }; try { Task.WaitAll(tasks); // wait 2 minutes after completed and then remove the task id //Task.Factory.StartNewDelayed(2 * 60 * 1000, () => _cacheClient.Remove(taskId)); } catch (Exception) { //Log.Error().Project(id).Exception(e).Message("Error resetting project data.").Report().Write(); } }