public void ConsumerTask() { try { MapSearchArgs searchArgs; MapSearchResult searchResult; while (true) { if (TasksMsn.TryPop(out searchArgs)) { searchResult = _mainMapDataGetter.FindMapData(searchArgs); _mainMapDataGetter.ProcessMapResult(searchResult); } Thread.Sleep(5); } } catch (ThreadAbortException ex) { //Console.WriteLine("Consumer thread aborted"); } finally { } }
public async void ConsumerTask() { try { IMapSearchArgs memorySearchArgs, msnSearchArgs; IMapSearchResult searchResult, lastSearchResult = null; var memorySearchFailed = false; while (true) { if (_isPoolingEnabled) { //Prioritize Memory events over MSN/other. if (TasksMemory.TryPop(out memorySearchArgs)) { _cancellationTokenSource = new CancellationTokenSource(); if (memorySearchArgs.MapId == 0 && string.IsNullOrEmpty(memorySearchArgs.MapHash)) { memorySearchFailed = true; } else { if (memorySearchArgs.EventType == OsuEventType.MapChange || lastSearchResult == null || !lastSearchResult.BeatmapsFound.Any()) { _logger.SetContextData("OsuMemory_searchingForBeatmaps", "1"); lastSearchResult = searchResult = _mainMapDataGetter.FindMapData(memorySearchArgs); _logger.SetContextData("OsuMemory_searchingForBeatmaps", "0"); } else { searchResult = new MapSearchResult(memorySearchArgs) { Mods = lastSearchResult.Mods }; searchResult.BeatmapsFound.AddRange(lastSearchResult.BeatmapsFound); } if (searchResult.BeatmapsFound.Any()) { memorySearchFailed = false; searchResult.MapSource = memorySearchArgs.SourceName; _logger.SetContextData("OsuMemory_searchResult", new { mods = searchResult.Mods?.Mods.ToString() ?? "null", rawName = $"{searchResult.BeatmapsFound[0].Artist} - {searchResult.BeatmapsFound[0].Title} [{searchResult.BeatmapsFound[0].DiffName}]", mapId = searchResult.BeatmapsFound[0].MapId.ToString(), action = searchResult.Action.ToString() }.ToString()); try { await _mainMapDataGetter.ProcessMapResult(searchResult, _cancellationTokenSource.Token); } catch (TaskCanceledException) { } } else { memorySearchFailed = true; } } } if (memorySearchFailed) { if (TasksMsn.TryPop(out msnSearchArgs)) { var status = memorySearchArgs?.Status ?? OsuStatus.Null; msnSearchArgs.Status = status != OsuStatus.Null ? status : msnSearchArgs.Status; searchResult = _mainMapDataGetter.FindMapData(msnSearchArgs); searchResult.MapSource = msnSearchArgs.SourceName; try { await _mainMapDataGetter.ProcessMapResult(searchResult, _cancellationTokenSource.Token); } catch (TaskCanceledException) { } } } } else { //Use MSN/other events only if (TasksMsn.TryPop(out msnSearchArgs)) { searchResult = _mainMapDataGetter.FindMapData(msnSearchArgs); searchResult.MapSource = msnSearchArgs.SourceName; await _mainMapDataGetter.ProcessMapResult(searchResult, _cancellationTokenSource.Token); } } Thread.Sleep(5); } } catch (ThreadAbortException) { } finally { } }
public void ConsumerTask() { try { bool isPoolingEnabled = _settings.Get <bool>(_names.EnableMemoryPooling); int counter = 0; MapSearchArgs memorySearchArgs; MapSearchArgs msnSearchArgs; MapSearchResult searchResult; var memorySearchFailed = false; while (true) { if (counter % 400 == 0) {//more or less every 2 seconds given 5ms delay at end. counter = 0; isPoolingEnabled = _settings.Get <bool>(_names.EnableMemoryPooling); } counter++; if (isPoolingEnabled) { //Here we prioritize Memory events over MSN/other. if (TasksMemory.TryPop(out memorySearchArgs)) { if (memorySearchArgs.MapId == 0 && string.IsNullOrEmpty(memorySearchArgs.MapHash)) { memorySearchFailed = true; } else { _logger.SetContextData("OsuMemory_searchingForBeatmaps", "1"); searchResult = _mainMapDataGetter.FindMapData(memorySearchArgs); _logger.SetContextData("OsuMemory_searchingForBeatmaps", "0"); if (searchResult.FoundBeatmaps) { memorySearchFailed = false; searchResult.EventSource = memorySearchArgs.SourceName; _logger.SetContextData("OsuMemory_searchResult", new { mods = searchResult.Mods?.Mods.ToString() ?? "null", rawName = $"{searchResult.BeatmapsFound[0].Artist} - {searchResult.BeatmapsFound[0].Title} [{searchResult.BeatmapsFound[0].DiffName}]", mapId = searchResult.BeatmapsFound[0].MapId.ToString(), action = searchResult.Action.ToString() }.ToString()); _mainMapDataGetter.ProcessMapResult(searchResult); } else { memorySearchFailed = true; } } } if (memorySearchFailed) { if (TasksMsn.TryPop(out msnSearchArgs)) { var status = memorySearchArgs?.Status ?? OsuStatus.Null; msnSearchArgs.Status = status != OsuStatus.Null ? status : msnSearchArgs.Status; searchResult = _mainMapDataGetter.FindMapData(msnSearchArgs); searchResult.EventSource = msnSearchArgs.SourceName; _mainMapDataGetter.ProcessMapResult(searchResult); } } } else { //Use MSN/other events only if (TasksMsn.TryPop(out msnSearchArgs)) { searchResult = _mainMapDataGetter.FindMapData(msnSearchArgs); searchResult.EventSource = msnSearchArgs.SourceName; _mainMapDataGetter.ProcessMapResult(searchResult); } } Thread.Sleep(5); } } catch (ThreadAbortException) { } finally { } }
public void ConsumerTask() { try { bool isPoolingEnabled = _settings.Get <bool>(_names.EnableMemoryPooling); int counter = 0; MapSearchArgs searchArgs; MapSearchResult searchResult; var memorySearchFailed = false; while (true) { if (counter % 400 == 0) {//more or less every 2 seconds given 5ms delay at end. counter = 0; isPoolingEnabled = _settings.Get <bool>(_names.EnableMemoryPooling); } counter++; if (isPoolingEnabled) { //Here we prioritize Memory events over MSN/other. if (TasksMemory.TryPop(out searchArgs)) { if (searchArgs.MapId == 0 && string.IsNullOrEmpty(searchArgs.MapHash)) { memorySearchFailed = true; } else { searchResult = _mainMapDataGetter.FindMapData(searchArgs); if (searchResult.FoundBeatmaps) { memorySearchFailed = false; searchResult.EventSource = searchArgs.SourceName; _mainMapDataGetter.ProcessMapResult(searchResult); } else { memorySearchFailed = true; } } } if (memorySearchFailed) { if (TasksMsn.TryPop(out searchArgs)) { searchResult = _mainMapDataGetter.FindMapData(searchArgs); searchResult.EventSource = searchArgs.SourceName; _mainMapDataGetter.ProcessMapResult(searchResult); } } } else { //Use MSN/other events only if (TasksMsn.TryPop(out searchArgs)) { searchResult = _mainMapDataGetter.FindMapData(searchArgs); searchResult.EventSource = searchArgs.SourceName; _mainMapDataGetter.ProcessMapResult(searchResult); } } Thread.Sleep(5); } } catch (ThreadAbortException ex) { //Console.WriteLine("Consumer thread aborted"); } finally { } }