Commit 78155ccb authored by justcoding121's avatar justcoding121

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

parent 5c4fc480
using System; using System;
using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Examples.Basic namespace Titanium.Web.Proxy.Examples.Basic
...@@ -9,11 +10,14 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -9,11 +10,14 @@ namespace Titanium.Web.Proxy.Examples.Basic
public static void Main(string[] args) 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 //On Console exit make sure we also exit the proxy
NativeMethods.Handler = ConsoleEventCallback; NativeMethods.Handler = ConsoleEventCallback;
NativeMethods.SetConsoleCtrlHandler(NativeMethods.Handler, true); NativeMethods.SetConsoleCtrlHandler(NativeMethods.Handler, true);
//Start proxy controller //Start proxy controller
controller.StartProxy(); controller.StartProxy();
...@@ -42,6 +46,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -42,6 +46,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
internal static class NativeMethods internal static class NativeMethods
{ {
internal const uint ENABLE_EXTENDED_FLAGS = 0x0080;
// Keeps it from getting garbage collected // Keeps it from getting garbage collected
internal static ConsoleEventDelegate Handler; internal static ConsoleEventDelegate Handler;
...@@ -50,5 +56,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -50,5 +56,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
// Pinvoke // Pinvoke
internal delegate bool ConsoleEventDelegate(int eventType); 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