Skip to content

Commit

Permalink
Updating C# Examples: Interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
metadings committed Jan 24, 2015
1 parent 5848f7d commit 5593267
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/C#/ZGuideExamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<Commandlineparameters>PPQueue Ulrich0</Commandlineparameters>
<Commandlineparameters>Interrupt</Commandlineparameters>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
Expand Down
69 changes: 35 additions & 34 deletions examples/C#/interrupt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,42 @@ public static void Interrupt(IDictionary<string, string> dict, string[] args)
{
Console.CancelKeyPress += (sender, e) =>
{
// e.Cancel = false;
context.Terminate();
e.Cancel = false;
// context.Terminate();
};

var thread = new Thread(() =>
responder.Bind("tcp://*:5555");

var error = ZError.None;
ZFrame request;
while (true)
{
while (true)
if (Console.KeyAvailable)
{
if (Console.KeyAvailable)
ConsoleKeyInfo info = Console.ReadKey(true);
if (info.Modifiers == ConsoleModifiers.Control && info.Key == ConsoleKey.C)
{
ConsoleKeyInfo info = Console.ReadKey(true);
if (info.Modifiers == ConsoleModifiers.Control && info.Key == ConsoleKey.C)
{
break;
}
if (info.Key == ConsoleKey.Escape)
{
context.Terminate();
break;
}
// error = ZError.ETERM;
// break;
context.Terminate();
}
if (info.Key == ConsoleKey.Escape)
{
context.Terminate();
}
Thread.Sleep(1);
}
});
thread.Start();
thread.Join(64);


responder.Bind("tcp://*:5555");

ZError error;
ZFrame request;
while (true)
{
if (null == (request = responder.ReceiveFrame(out error)))
if (null == (request = responder.ReceiveFrame(ZSocketFlags.DontWait, out error)))
{
if (error == ZError.ETERM)
if (error == ZError.EAGAIN)
{
Console.WriteLine("Terminating, you have pressed ESC.");
break;
error = ZError.None;
Thread.Sleep(1);

continue;
}
if (error == ZError.ETERM)
break; // Interrupted
throw new ZException(error);
}

Expand All @@ -78,15 +73,21 @@ public static void Interrupt(IDictionary<string, string> dict, string[] args)
if (!responder.Send(response, out error))
{
if (error == ZError.ETERM)
{
Console.WriteLine("Terminating, you have pressed ESC.");
break;
}
break; // Interrupted
throw new ZException(error);
}
}
}
}

if (error == ZError.ETERM)
{
Console.WriteLine("Terminating, you have pressed ESC.");
}
else
{
throw new ZException(error);
}
}
}
}
Expand Down

0 comments on commit 5593267

Please sign in to comment.