当前位置: 首页>>代码示例>>C#>>正文


C# UnixSignal.Reset方法代码示例

本文整理汇总了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;
		}
开发者ID:dms-cmt,项目名称:hangman-service,代码行数:56,代码来源:Program.cs

示例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 ();
		}
开发者ID:handyyuan,项目名称:playscript,代码行数:20,代码来源:UnixSignalTest.cs

示例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 ();
			}
		}
	}
开发者ID:bvanreeven,项目名称:mono,代码行数:75,代码来源:mono-service.cs


注:本文中的Mono.Unix.UnixSignal.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。