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


C# EventWaitHandle.WaitOne方法代码示例

本文整理汇总了C#中System.Threading.EventWaitHandle.WaitOne方法的典型用法代码示例。如果您正苦于以下问题:C# EventWaitHandle.WaitOne方法的具体用法?C# EventWaitHandle.WaitOne怎么用?C# EventWaitHandle.WaitOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.EventWaitHandle的用法示例。


在下文中一共展示了EventWaitHandle.WaitOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {

            var done = new EventWaitHandle(false, EventResetMode.AutoReset);

            var yield = new Thread(
                new ParameterizedThreadStart(
                    data =>
                    {
                        Console.WriteLine(new { data });

                        done.Set();
                    }
                )
            );

            Console.WriteLine("before wait " + DateTime.Now);

            // Additional information: Thread has not been started.
            done.WaitOne(2100);

            Console.WriteLine("after wait " + DateTime.Now);

            yield.Start(new { foo = "bar" });

            done.WaitOne();

            Console.WriteLine("done");

            CLRProgram.CLRMain();
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:31,代码来源:Program.cs

示例2: Main

        public static void Main()
        {
            // 1. 로그헬퍼 환경설정 읽기 - 클라이언트에서 xml파일로 환경설정 읽기
            LogHelper.XMLConfiguratorLoader.Loader("LogHelperXMLConfigure.txt");
            // 2. 프로그램 버전 설정
            LogHelper.XMLConfiguratorLoader.ProgramVersion = "1.0.0.0";

            // 3. 기본LogHelper를 등록 한다.
            LogHelper.LogHelper.AddLogHelper(LogHelperType.Default, "사용자 아이디");

            _ewh = new EventWaitHandle(false, EventResetMode.AutoReset);
            Console.WriteLine("동기화 처리된 스레드 시작");

            Thread T1 = new Thread(
                    new ThreadStart(ThreadProc1)
                );
            T1.Start();
            _ewh.WaitOne();

            Thread T2 = new Thread(
                    new ThreadStart(ThreadProc2)
                );
            T2.Start();
            _ewh.WaitOne();
            _ewh.Reset();
        }
开发者ID:tyeom,项目名称:LogHelper,代码行数:26,代码来源:Program.cs

示例3: First

        public IEnumerable<int> First(EventWaitHandle wait)
        {
            wait.WaitOne();
            yield return 0;

            wait.WaitOne();
            yield return 1;
        }
开发者ID:adymitruk,项目名称:openwrap,代码行数:8,代码来源:MultiThreaded_specs.cs

示例4: Second

        public IEnumerable<int> Second(EventWaitHandle wait)
        {
            wait.WaitOne();
            yield return 5;

            wait.WaitOne();
            yield return 6;
        }
开发者ID:adymitruk,项目名称:openwrap,代码行数:8,代码来源:MultiThreaded_specs.cs

示例5: ChangeCollection

 public void ChangeCollection()
 {
   _handle = new EventWaitHandle(false, EventResetMode.ManualReset);
   var test = new ObservableDictionary<int, string>();
   test.Changed += Dictionary_Changed;
   test.Add(0, "myValue");
   Assert.IsTrue(_handle.WaitOne(10), "Add() is not recognized as a change");
   _handle.Reset();
   test[0] = "newValue";
   Assert.IsTrue(_handle.WaitOne(10), "this[] is not recognized as a change");
   _handle.Reset();
   test.Remove(0);
   Assert.IsTrue(_handle.WaitOne(10), "Remove() is not recognized as a change");
 }
开发者ID:rnpowerconsulting,项目名称:appstract,代码行数:14,代码来源:ObservableDictionaryTests.cs

示例6: RunInThreadPoolWithEvents

        static void RunInThreadPoolWithEvents()
        {
            double result = 0d;

            // We use this event to signal when the thread is don executing.
            EventWaitHandle calculationDone = new EventWaitHandle(false, EventResetMode.AutoReset);

            // Create a work item to read from I/O
            ThreadPool.QueueUserWorkItem((x) => {
                result += Utils.CommonFunctions.ReadDataFromIO();
                calculationDone.Set();
            });

            // Save the result of the calculation into another variable
            double result2 = Utils.CommonFunctions.DoIntensiveCalculations();

            // Wait for the thread to finish
            calculationDone.WaitOne();

            // Calculate the end result
            result += result2;

            // Print the result
            Console.WriteLine("The result is {0}", result);
        }
开发者ID:vikramadhav,项目名称:Certification_70-483,代码行数:25,代码来源:Program.cs

示例7: DisposeTimer

 public static void DisposeTimer(Timer timer)
 {
     Check.Require(timer, "timer");
     var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
     timer.Dispose(waitHandle);
     waitHandle.WaitOne(1000);
 }
开发者ID:HNeukermans,项目名称:Hallo,代码行数:7,代码来源:SipUtil.cs

示例8: CrashTestBeforeMerge

        public void CrashTestBeforeMerge()
        {
            string path = Path.GetFullPath ("TestData\\CrashTestBeforeMerge");
            using (var db = new KeyValueStore(path)) db.Truncate ();

            var doneSetting = new EventWaitHandle (false, EventResetMode.ManualReset, "CrashTestBeforeMerge");
            doneSetting.Reset ();

            string testPath = Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().GetName ().CodeBase), "RazorTest.exe");
            var process = Process.Start (testPath, "CrashTestBeforeMerge");

            doneSetting.WaitOne (30000);
            if (!process.HasExited) {
                process.Kill ();
                process.WaitForExit ();
            }

            // Open the database created by the other program
            using (var db = new KeyValueStore(path)) {
                db.Manifest.Logger = (msg) => Console.WriteLine (msg);

                Console.WriteLine ("Begin enumeration.");
                ByteArray lastKey = new ByteArray ();
                int ct = 0;
                foreach (var pair in db.Enumerate()) {
                    ByteArray k = new ByteArray (pair.Key);
                    Assert.True (lastKey.CompareTo (k) < 0);
                    lastKey = k;
                    ct++;
                }
                Assert.AreEqual (10000, ct);
                Console.WriteLine ("Found {0} items in the crashed database.", ct);
            }
        }
开发者ID:T145,项目名称:razordbx,代码行数:34,代码来源:CrashTests.cs

示例9: Sleep

		public static void Sleep(int millisecondsTimeout)
		{
			using (var handle = new EventWaitHandle(false, EventResetMode.ManualReset))
			{
				handle.WaitOne(millisecondsTimeout);
			}
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:7,代码来源:Thread.cs

示例10: bgWorker_DoWork

        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                long waketime = (long)e.Argument;

                using (SafeWaitHandle handle = CreateWaitableTimer(IntPtr.Zero, true, GetType().Assembly.GetName().Name + "Timer"))
                {
                    if (SetWaitableTimer(handle, ref waketime, 0, IntPtr.Zero, IntPtr.Zero, true))
                    {
                        using (EventWaitHandle wh = new EventWaitHandle(false,
                                                               EventResetMode.AutoReset))
                        {
                            wh.SafeWaitHandle = handle;
                            wh.WaitOne();
                        }
                    }
                    else
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error scheduling wake timer", ex);
            }
        }
开发者ID:Cyrre,项目名称:Emby,代码行数:28,代码来源:WindowsPowerManagement.cs

示例11: ForceOnce

    public bool ForceOnce()
    {
      Process process = Process.GetProcessById(_processId);
      if (process == null || process.HasExited)
        throw new InvalidOperationException("Cannot force focus, process is not running");

      _waitHandle = new AutoResetEvent(false);

      try
      {
        Win32.EnumWindowsProc ewc = CheckWindow;

        int focusedId = Win32.GetForegroundWindowPID();
        if (focusedId != _processId)
        {
          _windowHandle = IntPtr.Zero;
          Win32.EnumerateWindows(ewc, IntPtr.Zero);

          bool waitResult = _waitHandle.WaitOne(5000, false);
          if (waitResult && _windowHandle != IntPtr.Zero)
            return Win32.SetForegroundWindow(_windowHandle, true);
        }
      }
      finally
      {
        _waitHandle.Close();
        _waitHandle = null;
      }

      return false;
    }
开发者ID:astalavister,项目名称:IR-Server-Suite,代码行数:31,代码来源:FocusForcer.cs

示例12: CreateWorkers

        private static IList<Thread> CreateWorkers(EventWaitHandle ewh, Action action, int threadsNum, int cycles)
        {
            var threads = new Thread[threadsNum];

            for (int i = 0; i < threadsNum; i++)
            {
                Action d = () =>
                {
                    Console.WriteLine("Waiting");

                    // NOTE: all threads should wait here for a signal from the main thread.
                    ewh.WaitOne();
                    Console.WriteLine("Done");

                    for (int j = 0; j < cycles; j++)
                    {
                        action();
                    }
                };

                Thread thread = new Thread(new ThreadStart(d)); ; // TODO: Create a new thread that will run the delegate above here.
                threads[i] = thread;
            }

            return threads;
        }
开发者ID:RomanMakarov1002,项目名称:EPAM.RD.2016S.Makarau,代码行数:26,代码来源:Program.cs

示例13: Should_be_able_to_cancel_message_reception_upon_disposal

        public void Should_be_able_to_cancel_message_reception_upon_disposal()
        {
            const string mmfName = "Local\\test";
            var message = "not null";
            var messageCancelled = new EventWaitHandle(false, EventResetMode.ManualReset, mmfName + "_MessageCancelled");

            messageCancelled.Set();

            var messageReceiver = new MemoryMappedFileMessageReceiver(mmfName);

            var task = new Task(() => message = messageReceiver.ReceiveMessage(ReadString));

            task.Start();

            var isSet = true;

            while (isSet)
                isSet = messageCancelled.WaitOne(0);

            messageReceiver.Dispose();

            task.Wait();

            message.ShouldBeNull();
        }
开发者ID:kushniro,项目名称:MemoryMessagePipe,代码行数:25,代码来源:Tests.cs

示例14: ServerResponds

 public void ServerResponds() {
   using (var container = SetupMefContainer()) {
     using (var server = container.GetExport<IServerProcessProxy>().Value) {
       var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
       var request = new IpcRequest {
         RequestId = 5,
         Protocol = IpcProtocols.Echo,
         Data = new IpcStringData {
           Text = "sdfsdsd"
         }
       };
       IpcResponse response = null;
       server.RunAsync(request, x => {
         response = x;
         waitHandle.Set();
       });
       Assert.IsTrue(waitHandle.WaitOne(TimeSpan.FromSeconds(5.0)), "Server did not respond within 5 seconds.");
       Assert.AreEqual(5, response.RequestId);
       Assert.AreEqual(IpcProtocols.Echo, response.Protocol);
       Assert.IsNotNull(request.Data);
       Assert.IsNotNull(response.Data);
       Assert.AreEqual(request.Data.GetType(), typeof(IpcStringData));
       Assert.AreEqual(response.Data.GetType(), typeof(IpcStringData));
       Assert.AreEqual((request.Data as IpcStringData).Text, (response.Data as IpcStringData).Text);
     }
   }
 }
开发者ID:mbbill,项目名称:vs-chromium,代码行数:27,代码来源:TestEchoProtocol.cs

示例15: AuthSignIn

        void AuthSignIn()
        {
            EventWaitHandle wait = new EventWaitHandle(false, EventResetMode.ManualReset);
            SlackSocketClient client = new SlackSocketClient(token);
            client.OnHello += () =>
            {
                wait.Set();
            };
            client.Connect((l) =>
            {

                if (!l.ok) return;

                BeginInvoke(new Action(() =>
                {
                    connected = new ConnectedInterface(client, l);
                    connected.Dock = DockStyle.Fill;

                    Controls.Add(connected);

                    password.Visible = false;
                }));
            });
            wait.WaitOne();
        }
开发者ID:seanfuture,项目名称:Slack,代码行数:25,代码来源:PrimaryInterface.cs


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