Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Management;
public class Program
{
public static void Main(string[] args)
{
using (var watcher = new Win32PowerManagementEventWatcher())
{
watcher.Start();
@eric-b
eric-b / NativeMethods.cs
Created April 6, 2016 18:18
SetConsoleCtrlHandler
using System.Runtime.InteropServices;
namespace ConsoleDemo
{
internal static class NativeMethods
{
// Doc MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686016(v=vs.85).aspx
/// <summary>
/// <para>Adds or removes an <see cref="HandlerRoutine"/> delegate function
@eric-b
eric-b / NativeMethods.cs
Last active August 29, 2015 14:04
Sample of typical code inside a NativeMethods.cs file.
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections.Generic;
internal static class NativeMethods
{
public static class NtDll