public void Execute(Action action)
        {
            string key = Guid.NewGuid().ToString();
            int    res = RmStartSession(out IntPtr handle, 0, key);

            if (res == 0)
            {
                ReportProgress?.Invoke($"Restart Manager session created with ID {key}");

                RM_UNIQUE_PROCESS[] processes = GetProcesses("explorer");
                res = RmRegisterResources(
                    handle,
                    0, null,
                    (uint)processes.Length, processes,
                    0, null
                    );

                if (res == 0)
                {
                    ReportProgress?.Invoke("Successfully registered resources.");

                    res = RmShutdown(handle, RM_SHUTDOWN_TYPE.RmForceShutdown, (percent) => ReportPercentage?.Invoke(percent));

                    if (res == 0)
                    {
                        ReportProgress?.Invoke("Applications stopped successfully.");
                        action();

                        res = RmRestart(handle, 0, (percent) => ReportPercentage?.Invoke(percent));

                        if (res == 0)
                        {
                            ReportProgress?.Invoke("Applications restarted successfully.");
                        }
                    }
                }

                res = RmEndSession(handle);

                if (res == 0)
                {
                    ReportProgress?.Invoke("Restart Manager session ended.");
                }
            }
        }
 private void OnReportPercentage(ReportPercentageEventArgs e)
 {
     ReportPercentage?.Invoke(this, e);
 }