private void BackgroundWorker_DoWork(object tokenObject) { var cancellationToken = (CancellationToken)tokenObject; while (!cancellationToken.IsCancellationRequested) { try { if (!spotifyHooked) { HookSpotify(); } StringBuilder result = GetSpotifyInfo(_spotify.GetStatus()); Preview = result.ToString(); RivaTuner.print(result.ToString()); Task.Delay(500, cancellationToken).Wait(cancellationToken); //Wait half a second to write again } catch (OperationCanceledException) { ClearScreen(); return; } catch { ClearScreen(); } } }
/// <summary> /// Writes a empty string to the screen for cleaning rivatuner of junk because it doesn't update if the applicatin suddenly stops /// </summary> public static void ClearScreen() { RivaTuner.print(String.Empty); }