本文整理汇总了C#中Mono.Unix.UnixSignal.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# UnixSignal.Reset方法的具体用法?C# UnixSignal.Reset怎么用?C# UnixSignal.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Unix.UnixSignal
的用法示例。
在下文中一共展示了UnixSignal.Reset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: TestDispose2
public void TestDispose2 ()
{
UnixSignal a = new UnixSignal (Signum.SIGINT);
UnixSignal b = new UnixSignal (Signum.SIGINT);
Stdlib.raise (Signum.SIGINT);
SleepUntilSignaled (a);
Assert.AreEqual (a.Count, 1);
Assert.AreEqual (b.Count, 1);
b.Close ();
a.Reset ();
Stdlib.raise (Signum.SIGINT);
SleepUntilSignaled (a);
Assert.AreEqual (a.Count, 1);
a.Close ();
}
示例3: MainLoop
// The main service loop
private void MainLoop (ServiceBase [] services)
{
try {
ServiceBase service;
if (services == null || services.Length == 0){
error (logname, "No services were registered by this service");
return;
}
// Start up the service.
service = null;
if (name != null){
foreach (ServiceBase svc in services){
if (svc.ServiceName == name){
service = svc;
break;
}
}
} else {
service = services [0];
}
if (service.ExitCode != 0) {
//likely due to a previous execution, so we need to reset it to default
service.ExitCode = 0;
}
call (service, "OnStart", args);
info (logname, "Service {0} started", service.ServiceName);
UnixSignal intr = new UnixSignal (Signum.SIGINT);
UnixSignal term = new UnixSignal (Signum.SIGTERM);
UnixSignal usr1 = new UnixSignal (Signum.SIGUSR1);
UnixSignal usr2 = new UnixSignal (Signum.SIGUSR2);
UnixSignal[] sigs = new UnixSignal[]{
intr,
term,
usr1,
usr2
};
for (bool running = true; running; ){
int idx = UnixSignal.WaitAny (sigs);
if (idx < 0 || idx >= sigs.Length)
continue;
if ((intr.IsSet || term.IsSet) && service.CanStop) {
intr.Reset ();
term.Reset ();
info (logname, "Stopping service {0}", service.ServiceName);
call (service, "OnStop", null);
if (service.ExitCode != 0)
error (logname, "Service stopped with a non-zero ExitCode: {0}", service.ExitCode);
running = false;
}
else if (usr1.IsSet && service.CanPauseAndContinue) {
usr1.Reset ();
info (logname, "Pausing service {0}", service.ServiceName);
call (service, "OnPause", null);
}
else if (usr2.IsSet && service.CanPauseAndContinue) {
usr2.Reset ();
info (logname, "Continuing service {0}", service.ServiceName);
call (service, "OnContinue", null);
}
}
} finally {
// Clean up
foreach (ServiceBase svc in services){
svc.Dispose ();
}
}
}