-
-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
060eded
commit 35bbf66
Showing
2 changed files
with
52 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Microsoft.WindowsAPICodePack.Taskbar; | ||
using System; | ||
|
||
namespace BenchmarkDotNet.Helpers | ||
{ | ||
internal class TaskbarProgress : IDisposable | ||
{ | ||
private IntPtr consoleWindowHandle = IntPtr.Zero; | ||
|
||
[System.Runtime.InteropServices.DllImport("kernel32.dll")] | ||
private static extern IntPtr GetConsoleWindow(); | ||
|
||
internal TaskbarProgress() | ||
{ | ||
if (TaskbarManager.IsPlatformSupported) | ||
{ | ||
consoleWindowHandle = GetConsoleWindow(); | ||
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal, consoleWindowHandle); | ||
Console.CancelKeyPress += OnConsoleCancelEvent; | ||
} | ||
} | ||
|
||
internal void SetProgress(int currentValue, int maximumValue) | ||
{ | ||
if (consoleWindowHandle != IntPtr.Zero) | ||
{ | ||
TaskbarManager.Instance.SetProgressValue(currentValue, maximumValue, consoleWindowHandle); | ||
} | ||
} | ||
|
||
private void OnConsoleCancelEvent(object sender, ConsoleCancelEventArgs e) | ||
{ | ||
Dispose(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (consoleWindowHandle != IntPtr.Zero) | ||
{ | ||
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress, consoleWindowHandle); | ||
consoleWindowHandle = IntPtr.Zero; | ||
Console.CancelKeyPress -= OnConsoleCancelEvent; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters