本文整理汇总了C#中Mono.Unix.UnixSignal.WaitOne方法的典型用法代码示例。如果您正苦于以下问题:C# UnixSignal.WaitOne方法的具体用法?C# UnixSignal.WaitOne怎么用?C# UnixSignal.WaitOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Unix.UnixSignal
的用法示例。
在下文中一共展示了UnixSignal.WaitOne方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNestedInvocation
public void TestNestedInvocation()
{
UnixSignal s = new UnixSignal(Signum.SIGINT);
Thread a = new Thread(delegate() {
bool r = s.WaitOne (1000, false);
});
Thread b = new Thread(delegate() {
bool r = s.WaitOne (500, false);
});
a.Start();
b.Start();
a.Join();
b.Join();
}
示例2: CreateWaitSignalThread
// helper method to create a thread waiting on a UnixSignal
static Thread CreateWaitSignalThread (UnixSignal signal, int timeout)
{
Thread t1 = new Thread(delegate() {
DateTime start = DateTime.Now;
bool r = signal.WaitOne (timeout, false);
DateTime end = DateTime.Now;
Assert.AreEqual (signal.Count, 1);
Assert.AreEqual (r, true);
if ((end - start) > new TimeSpan (0, 0, timeout/1000))
throw new InvalidOperationException ("Signal slept too long");
});
return t1;
}
示例3: TestNoEmit
public void TestNoEmit ()
{
using (UnixSignal u = new UnixSignal (Signum.SIGINT)) {
DateTime start = DateTime.Now;
bool r = u.WaitOne (5100, false);
Assert.AreEqual (r, false);
DateTime end = DateTime.Now;
if ((end - start) < new TimeSpan (0, 0, 5))
throw new InvalidOperationException ("Signal didn't block for 5s; blocked for " + (end-start).ToString());
}
}
示例4: TestRaise
public void TestRaise ()
{
Thread t1 = new Thread (delegate () {
using (UnixSignal a = new UnixSignal (Signum.SIGINT)) {
DateTime start = DateTime.Now;
bool r = a.WaitOne (5000, false);
DateTime end = DateTime.Now;
Assert.AreEqual (a.Count, 1);
Assert.AreEqual (r, true);
if ((end - start) > new TimeSpan (0, 0, 5))
throw new InvalidOperationException ("Signal slept too long");
}
});
Thread t2 = new Thread (delegate () {
Thread.Sleep (1000);
Stdlib.raise (Signum.SIGINT);
});
t1.Start ();
t2.Start ();
t1.Join ();
t2.Join ();
}
示例5: SetControlCHandler
internal static void SetControlCHandler()
{
if (Utilities.IsWindows)
{
if (!_windowsConsoleHandlerSet)
Console.CancelKeyPress += ConsoleControlCHandler;
_windowsConsoleHandlerSet = true;
}
else if (_signalThread == null)
{
Stdlib.SetSignalAction(Signum.SIGINT, SignalAction.Default);
_signalThread = new Thread(() =>
{
try
{
using (var sig = new UnixSignal(Signum.SIGINT))
{
while (true)
{
sig.WaitOne();
ControlCHandler();
}
}
}
catch (ThreadAbortException)
{
}
});
_signalThread.Start();
}
}
示例6: Main
static void Main()
{
Program.Games = new Dictionary<int, Game>();
dump_fname = Environment.GetEnvironmentVariable("OPENSHIFT_DATA_DIR")+"games.dump";
log_fname = Environment.GetEnvironmentVariable("OPENSHIFT_DIY_LOG_DIR") + "errors.log";
string data_dir = Environment.GetEnvironmentVariable("OPENSHIFT_DATA_DIR");
if (data_dir != null) {
System.IO.TextReader file = new System.IO.StreamReader(data_dir+"secret_token.txt", true);
SECRET = file.ReadToEnd();
file.Close();
}
if (System.IO.File.Exists(dump_fname))
{
System.IO.TextReader file = new System.IO.StreamReader(dump_fname, true);
string[] f = file.ReadToEnd().Split(new string[]{"\n"},StringSplitOptions.RemoveEmptyEntries);
foreach (string el in f)
{
string[] s = el.Split('@');
Program.Games.Add(int.Parse(s[0]),JsonConvert.DeserializeObject<Game>(s[1]));
}
file.Close();
}
try
{
WebSocket.Start();
}
catch (Exception e)
{
Log("Startup fatal error: "+e.ToString());
System.Environment.Exit(0);
}
Log("Start");
UnixSignal term = new UnixSignal(Signum.SIGTERM);
term.WaitOne();
Log("Terminate");
SaveGame();
System.Environment.Exit(0);
}