Commit 23f9ccff authored by justcoding121's avatar justcoding121 Committed by justcoding121

fix issue with console quickedit mode where app hangs until key press

parent 282634a9
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Examples.Basic
......@@ -9,11 +10,14 @@ namespace Titanium.Web.Proxy.Examples.Basic
public static void Main(string[] args)
{
//fix console hang due to QuickEdit mode
var handle = Process.GetCurrentProcess().MainWindowHandle;
NativeMethods.SetConsoleMode(handle, NativeMethods.ENABLE_EXTENDED_FLAGS);
//On Console exit make sure we also exit the proxy
NativeMethods.Handler = ConsoleEventCallback;
NativeMethods.SetConsoleCtrlHandler(NativeMethods.Handler, true);
//Start proxy controller
controller.StartProxy();
......@@ -42,6 +46,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
internal static class NativeMethods
{
internal const uint ENABLE_EXTENDED_FLAGS = 0x0080;
// Keeps it from getting garbage collected
internal static ConsoleEventDelegate Handler;
......@@ -50,5 +56,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
// Pinvoke
internal delegate bool ConsoleEventDelegate(int eventType);
[DllImport("kernel32.dll")]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment