Пример #1
0
        /// <summary>
        /// Creates and activates a new <see cref="ISleepInhibitor"/> for the current platform.
        /// </summary>
        public static ISleepInhibitor StartNew()
        {
            ISleepInhibitor inhibitor = CreateNew();

            inhibitor.IsInhibited = true;
            return(inhibitor);
        }
Пример #2
0
        public static void Main(String[] args)
        {
            CancellationTokenSource cancellation = new CancellationTokenSource();

            System.Console.CancelKeyPress +=
                (Object sender, ConsoleCancelEventArgs e) =>
            {
                e.Cancel = true;
                cancellation.Cancel();
            };

            using (ISleepInhibitor inhibitor = SleepInhibitor.StartNew())
            {
                System.Console.WriteLine("Espresso is keeping the computer awake.");
                System.Console.WriteLine("Press Ctrl+C to exit.");
                cancellation.Token.WaitHandle.WaitOne();
            }
        }