本文整理汇总了C#中Mono.Unix.UnixSignal类的典型用法代码示例。如果您正苦于以下问题:C# UnixSignal类的具体用法?C# UnixSignal怎么用?C# UnixSignal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnixSignal类属于Mono.Unix命名空间,在下文中一共展示了UnixSignal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
LogManager.LogFactory = new NLogFactory();
var appHost = new AppHost();
var appConfig = new TsonServiceConfig(args.Length > 0 ? args[0] : null, args.Length > 1 ? args[1] : null);
appHost.Container.Register<ITsonServiceConfig>(appConfig);
appHost.Init();
appHost.Start(appConfig.ServiceUrl);
UnixSignal[] signals = new UnixSignal[] {
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGTERM),
};
// Wait for a unix signal
for (bool exit = false; !exit;)
{
int id = UnixSignal.WaitAny(signals);
if (id >= 0 && id < signals.Length)
{
if (signals[id].IsSet)
exit = true;
}
}
}
示例2: Main
static void Main(string[] args)
{
var oledType = Util.ChooseOLEDType();
Console.WriteLine($"Running test with selected display [{oledType}]");
Console.WriteLine("Hit CTRL+C to stop");
var wr = new Wrapper(oledType);
wr.SetTextColor(1);
wr.SetTextSize(2);
UnixSignal sigint = new UnixSignal(Mono.Unix.Native.Signum.SIGINT);
while (!sigint.IsSet)
{
wr.ClearDisplay();
wr.SetCursor(0, 0);
var str = $"{DateTime.Now.ToString("HH:mm.ss")}";
Console.WriteLine(str);
wr.Print(str);
wr.Display();
Thread.Sleep(1000);
}
}
示例3: MultiThreadTest
// helper method to create a two-thread test
static void MultiThreadTest (UnixSignal signal, int timeout, ThreadStart tstart)
{
Thread t1 = CreateWaitSignalThread (signal, timeout);
Thread t2 = new Thread (tstart);
t1.Start ();
t2.Start ();
t1.Join ();
t2.Join ();
}
示例4: TestWaitAnyFailsWithMore64Signals
public void TestWaitAnyFailsWithMore64Signals()
{
UnixSignal s1 = new UnixSignal(Signum.SIGINT);
UnixSignal[] signals = new UnixSignal[65];
for (int i=0; i<65; ++i)
signals[i] = s1;
Assert.That(UnixSignal.WaitAny(signals, new TimeSpan(0,0,1)), Is.EqualTo(-1));
}
示例5: WaitForUnixStopSignal
static void WaitForUnixStopSignal()
{
UnixSignal[] signals = new UnixSignal[]
{
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGTERM)
};
UnixSignal.WaitAny(signals);
}
示例6: Main
static void Main(string[] args)
{
//Set up IO - (TODO, allow to be set in config file)
var RingerPower = new Raspberry.IO.GeneralPurpose.OutputPinConfiguration (Raspberry.IO.GeneralPurpose.ProcessorPin.Pin17);
var RingerOscillator = new Raspberry.IO.GeneralPurpose.OutputPinConfiguration (Raspberry.IO.GeneralPurpose.ProcessorPin.Pin18);
var HookSwitch = new Raspberry.IO.GeneralPurpose.InputPinConfiguration (Raspberry.IO.GeneralPurpose.ProcessorPin.Pin22)
{
Reversed = true
};
var DialPulseSwitch = new Raspberry.IO.GeneralPurpose.InputPinConfiguration (Raspberry.IO.GeneralPurpose.ProcessorPin.Pin27);
//Start Ringer and DialListener GPIO classes
using (var ringer = new clsRinger (RingerPower, RingerOscillator))
{
using (var dialListener = new clsDialHookListener(HookSwitch,DialPulseSwitch))
{
//Simple bell test function. 0 = UK ring, 1 = USA Ring
dialListener.NumberDialed += (uint NumberDialed) =>
{
Console.WriteLine("Number Dialed:{0}",NumberDialed);
if (NumberDialed == 0) {
ringer.SetRingPattern (clsRinger.ringPattern_UK);
ringer.StartRing ();
} else if (NumberDialed == 9) {
ringer.SetRingPattern (clsRinger.ringPattern_USA);
ringer.StartRing ();
}
};
//Cancel the Ringer
dialListener.HookSwitchChange += (bool OnHook, uint Pulse) =>
{
if (!OnHook)
ringer.StopRing ();
};
UnixSignal[] signals = new UnixSignal [] {
new UnixSignal (Mono.Unix.Native.Signum.SIGINT),
new UnixSignal (Mono.Unix.Native.Signum.SIGUSR1),
};
while (true)
{
int index = UnixSignal.WaitAny (signals, -1); //Wait for any Unix Signals
Mono.Unix.Native.Signum signal = signals [index].Signum;
Console.Write("SIGNAL:{0}",signal.ToString());
break;
}
;
}
}
Console.WriteLine ("**end**");
}
示例7: Main
public static int Main (string[] args)
{
using (ServiceHost host = new ServiceHost (typeof (HangmanService)))
{
var security = new SecurityMode ();
host.AddServiceEndpoint (
typeof(IHangmanService),
new WSHttpBinding (security, true),
"http://localhost:8325/");
host.Open ();
/*
Console.WriteLine ("Type [CR] to stop ...");
Console.ReadKey ();
*/
/* Demon */
UnixSignal sigint = new UnixSignal (Signum.SIGINT);
UnixSignal sigterm = new UnixSignal (Signum.SIGTERM);
UnixSignal sighup = new UnixSignal (Signum.SIGHUP);
UnixSignal sigusr2 = new UnixSignal (Signum.SIGUSR2);
UnixSignal [] signals = new UnixSignal[]
{
sigint,
sigterm,
sighup,
sigusr2
};
bool exit = false;
while (!exit)
{
int id = UnixSignal.WaitAny (signals);
if (id >= 0 && id < signals.Length)
{
if (sigint.IsSet || sigterm.IsSet)
{
sigint.Reset ();
sigterm.Reset ();
exit = true;
} else if (sighup.IsSet)
sighup.Reset ();
else if (sigusr2.IsSet)
sighup.Reset ();
}
}
/* Demon */
host.Close ();
}
return 0;
}
示例8: SignalHandler
public static void SignalHandler()
{
var sig = new UnixSignal( Mono.Unix.Native.Signum.SIGUSR2 );
var sigs = new UnixSignal[] { sig };
do {
UnixSignal.WaitAny( sigs, new TimeSpan(0,1,0) );
covertool.SaveData();
} while ( debugee != null && !debugee.HasExited );
}
示例9: InitSignals
static void InitSignals()
{
UnixSignal term = new UnixSignal (Mono.Unix.Native.Signum.SIGTERM);
UnixSignal inter = new UnixSignal (Mono.Unix.Native.Signum.SIGINT);
GLib.Timeout.Add (500, delegate {
if (term.IsSet || inter.IsSet)
Application.Quit ();
return true;
});
}
示例10: 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;
}
示例11: LinuxHandler
private void LinuxHandler()
{
Log.Notice("Linux", "Initializing Handler for SIGINT, SIGHUP");
var signals = new UnixSignal[]
{
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGHUP)
};
int which = UnixSignal.WaitAny(signals, -1);
Log.Debug("Linux", "Got a {0} signal!", signals[which].Signum);
Log.Notice("Linux", "Handler Terminated.");
MainClass.Shutdown();
}
示例12: 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();
}
示例13: LinuxHandler
protected virtual void LinuxHandler()
{
Log.Notice("Linux", sLConsole.GetString("Initializing Handler for SIGINT, SIGHUP"));
var signals = new UnixSignal[]
{
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGHUP)
};
int which = UnixSignal.WaitAny(signals, -1);
Log.Debug("Linux", sLConsole.GetString("Got a {0} signal."), signals[which].Signum);
Log.Notice("Linux", sLConsole.GetString("Handler Terminated."));
Action();
}
示例14: UnixExitSignal
public UnixExitSignal()
{
UnixSignal[] signals = new UnixSignal[]
{
new UnixSignal(Signum.SIGTERM),
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGUSR1),
};
Task.Factory.StartNew(() =>
{
int index = UnixSignal.WaitAny(signals, Timeout.Infinite);
if (Signaled != null)
Signaled(this, EventArgs.Empty);
});
}
示例15: Attach
internal static void Attach(Entry plugin)
{
if (Tools.RuntimePlatform != OTA.Misc.RuntimePlatform.Microsoft)
{
try
{
if (!_attached)
{
_attached = true;
// Catch SIGINT, SIGUSR1 and SIGTERM
UnixSignal[] signals = new UnixSignal[]
{
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGUSR1),
new UnixSignal(Signum.SIGTERM)
};
(signal_thread = new Thread(delegate ()
{
System.Threading.Thread.CurrentThread.Name = "SIG";
while (!Terraria.Netplay.disconnect && _attached)
{
// Wait for a signal to be delivered
var index = UnixSignal.WaitAny(signals, -1);
var signal = signals[index].Signum;
if (!Terraria.Netplay.disconnect && _attached)
{
_attached = false;
OTA.Logging.ProgramLog.Log("Server received Exit Signal");
VanillaCommands.Exit(null, null);
}
}
})).Start();
}
OTA.Logging.ProgramLog.Log("Server can accept SIGTERM");
}
catch
{
OTA.Logging.ProgramLog.Log("Failed to attatch SIGTERM listener");
}
}
}