title: Winforms - C# Taskbar Progress Indicator (Windows 10)
body: <p>Using C#* <strong>Windows Forms</strong> on <strong>Windows 10</strong>, is there a way to set up a <strong>progress indicator</strong> on the <strong>taskbar</strong> icon? While searching for it almost all the results were directed to Windows 7. I tried using <em>WindowsAPICodePack</em>, <em>TaskbarItemInfo</em>, <em>TaskbarManager</em> and others. None worked. Here are some snippets of code:</p>
  <pre><code>taskBarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
  
  for (int i = 0; i &lt; 100; i++)
  {
      taskBarItemInfo.ProgressValue = i / 100.0;
      Thread.Sleep(50); // whatever the 'work' really is
  }
  
  taskBarItemInfo.ProgressState = TaskbarItemProgressState.None;
  </code></pre>
  <pre><code>using System;
  using System.Runtime.InteropServices;
  
  public static class TaskbarProgress
  {
      public enum TaskbarStates
      {
          NoProgress    = 0,
          Indeterminate = 0x1,
          Normal        = 0x2,
          Error         = 0x4,
          Paused        = 0x8
      }
  
      [ComImport()]
      [Guid(&quot;ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf&quot;)]
      [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
      private interface ITaskbarList3
      {
          // ITaskbarList
          [PreserveSig]
          void HrInit();
          [PreserveSig]
          void AddTab(IntPtr hwnd);
          [PreserveSig]
          void DeleteTab(IntPtr hwnd);
          [PreserveSig]
          void ActivateTab(IntPtr hwnd);
          [PreserveSig]
          void SetActiveAlt(IntPtr hwnd);
  
          // ITaskbarList2
          [PreserveSig]
          void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
  
          // ITaskbarList3
          [PreserveSig]
          void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
          [PreserveSig]
          void SetProgressState(IntPtr hwnd, TaskbarStates state);
      }
  
      [ComImport()]    
      [Guid(&quot;56fdf344-fd6d-11d0-958a-006097c9a090&quot;)]
      [ClassInterface(ClassInterfaceType.None)]
      private class TaskbarInstance
      {
      }
  
      private static ITaskbarList3 taskbarInstance = (ITaskbarList3)new TaskbarInstance();
      private static bool taskbarSupported = Environment.OSVersion.Version &gt;= new Version(6, 1);
  
      public static void SetState(IntPtr windowHandle, TaskbarStates taskbarState)
      {
          if (taskbarSupported) taskbarInstance.SetProgressState(windowHandle, taskbarState);
      }
  
      public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax)
      {
          if (taskbarSupported) taskbarInstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax);
      }
  }
  </code></pre>
  <pre><code>TaskbarProgress.SetValue(this.Handle, 50, 100);
  TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Indeterminate);
  </code></pre>
  <p>* My project currently uses .NET Framework 4.7.2</p>
  <p>Thanks in advance</p>