Skip to content

Commit

Permalink
Changed Application.DoEvents to Application.Run() in console applicat…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
gmamaladze committed Jan 24, 2018
1 parent f70ef24 commit 453ab91
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion MouseKeyHook/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
)]
[assembly: AssemblyCopyright("(c) George Mamaladze 2000-2018")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("5.5.0")]
[assembly: AssemblyVersion("5.6.0")]
6 changes: 2 additions & 4 deletions examples/ConsoleHook.Rx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ private static void Main(string[] args)
.Select(p => p.Value).FirstOrDefault();
}
Console.WriteLine("--------------------------------------------------");
action(quit);

while (!quit.WaitOne(100))
Application.DoEvents();
;
action(quit);
Application.Run(new ApplicationContext());
}

private static void Exit(AutoResetEvent quit)
Expand Down
4 changes: 2 additions & 2 deletions examples/ConsoleHook/DetectCombinations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ConsoleHook
{
internal class DetectCombinations
{
public static void Do(AutoResetEvent quit)
public static void Do(Action quit)
{
var map = new Dictionary<Combination, Action>
{
Expand All @@ -23,7 +23,7 @@ public static void Do(AutoResetEvent quit)
{Combination.TriggeredBy(Keys.F).With(Keys.E).With(Keys.D), () => Console.WriteLine(":-D")},
{Combination.FromString("Alt+A"), () => Console.WriteLine(":-P")},
{Combination.FromString("Control+Shift+Z"), () => Console.WriteLine(":-/")},
{Combination.FromString("Escape"), () => quit.Set()}
{Combination.FromString("Escape"), quit}
};

Console.WriteLine("Detecting following combinations:");
Expand Down
4 changes: 2 additions & 2 deletions examples/ConsoleHook/DetectSequences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace ConsoleHook
{
internal class DetectSequences
{
public static void Do(AutoResetEvent quit)
public static void Do(Action quit)
{
var map = new Dictionary<Sequence, Action>
{
{Sequence.FromString("Control+Z,B"), Console.WriteLine},
{Sequence.FromString("Control+Z,Z"), Console.WriteLine},
{Sequence.FromString("Escape,Escape,Escape"), () => quit.Set()}
{Sequence.FromString("Escape,Escape,Escape"), quit}
};

Console.WriteLine("Detecting following combinations:");
Expand Down
5 changes: 3 additions & 2 deletions examples/ConsoleHook/LogKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ namespace ConsoleHook
{
internal class LogKeys
{
public static void Do(AutoResetEvent quit)
public static void Do(Action quit)
{
Console.WriteLine("Press Q to quit.");
Hook.GlobalEvents().KeyPress += (sender, e) =>
{
Console.Write(e.KeyChar);
if (e.KeyChar == 'q') quit.Set();
if (e.KeyChar == 'q') quit();
};
}
}
Expand Down
16 changes: 9 additions & 7 deletions examples/ConsoleHook/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace ConsoleHook
{
internal class Program
{
private static void Main(string[] args)
{
var quit = new AutoResetEvent(false);

var selector = new Dictionary<string, Action<AutoResetEvent>>
var selector = new Dictionary<string, Action<Action>>
{
{"1. Log keys", LogKeys.Do},
{"2. Detect key combinations", DetectCombinations.Do},
{"3. Detect key sequences", DetectSequences.Do},
{"Q. Quit", Exit}
};

Action<AutoResetEvent> action = null;
Action<Action> action = null;

while (action == null)
{
Expand All @@ -36,13 +35,16 @@ private static void Main(string[] args)
.Select(p => p.Value).FirstOrDefault();
}
Console.WriteLine("--------------------------------------------------");
action(quit);

action(Application.Exit);

Application.Run(new ApplicationContext());
}


private static void Exit(AutoResetEvent quit)
private static void Exit(Action quit)
{
quit.Set();
Application.Exit();
}
}
}

0 comments on commit 453ab91

Please sign in to comment.