當前位置: 首頁>>代碼示例>>C#>>正文


C# Unix.UnixSignal類代碼示例

本文整理匯總了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;
                }
            }
        }
開發者ID:jlyonsmith,項目名稱:Tson,代碼行數:27,代碼來源:Program.cs

示例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);
            }
        }
開發者ID:ChriszGitHub,項目名稱:ArduiPi_OLED,代碼行數:26,代碼來源:Program.cs

示例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 ();
		}
開發者ID:handyyuan,項目名稱:playscript,代碼行數:10,代碼來源:UnixSignalTest.cs

示例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));
		}
開發者ID:handyyuan,項目名稱:playscript,代碼行數:9,代碼來源:UnixSignalTest.cs

示例5: WaitForUnixStopSignal

 static void WaitForUnixStopSignal()
 {
     UnixSignal[] signals = new UnixSignal[]
                 {
                     new UnixSignal(Signum.SIGINT),
                     new UnixSignal(Signum.SIGTERM)
                 };
     UnixSignal.WaitAny(signals);
 }
開發者ID:mageomageos,項目名稱:animerecs,代碼行數:9,代碼來源:Program.cs

示例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**");
        }
開發者ID:logicethos,項目名稱:PiTelephone,代碼行數:57,代碼來源:Program.cs

示例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;
		}
開發者ID:dms-cmt,項目名稱:hangman-service,代碼行數:56,代碼來源:Program.cs

示例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 );
        }
開發者ID:Money520,項目名稱:XR.Baboon,代碼行數:10,代碼來源:Program.cs

示例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;
            });
        }
開發者ID:garuma,項目名稱:zencomic,代碼行數:12,代碼來源:Main.cs

示例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;
		}
開發者ID:handyyuan,項目名稱:playscript,代碼行數:14,代碼來源:UnixSignalTest.cs

示例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();
        }
開發者ID:Schumix,項目名稱:Schumix2,代碼行數:14,代碼來源:Linux.cs

示例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();
		}
開發者ID:handyyuan,項目名稱:playscript,代碼行數:14,代碼來源:UnixSignalTest.cs

示例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();
        }
開發者ID:Schumix,項目名稱:Schumix2,代碼行數:14,代碼來源:DefaultLinux.cs

示例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);
     });
 }
開發者ID:pferraris,項目名稱:DockerServices,代碼行數:15,代碼來源:UnixExitSignal.cs

示例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");
                }
            }
        }
開發者ID:carriercomm,項目名稱:Terraria-s-Dedicated-Server-Mod,代碼行數:44,代碼來源:Sigterm.cs


注:本文中的Mono.Unix.UnixSignal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。