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


C# WaitHandle.WaitOne方法代碼示例

本文整理匯總了C#中System.Threading.WaitHandle.WaitOne方法的典型用法代碼示例。如果您正苦於以下問題:C# WaitHandle.WaitOne方法的具體用法?C# WaitHandle.WaitOne怎麽用?C# WaitHandle.WaitOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Threading.WaitHandle的用法示例。


在下文中一共展示了WaitHandle.WaitOne方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: StartOnMySignal

        static WaitHandle StartOnMySignal(WaitHandle signalWhenReadyToStart, Action callback)
        {
            var exitHandle = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem(delegate
            {
                signalWhenReadyToStart.WaitOne();

                try
                {
                    var watch = Stopwatch.StartNew();

                    while (watch.Elapsed < maxExecutionTime)
                    {
                        callback();
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }
                finally
                {
                    exitHandle.Set();
                }
            });

            return exitHandle;
        }
開發者ID:davidd2k,項目名稱:OctoDB,代碼行數:29,代碼來源:Concurrency.cs

示例2: ShowDialog

        public DialogResult ShowDialog(MobileRemoteUI parentForm, WaitHandle waitResult, AddressSelector.BluetoothDevice device, BluetoothHidWriter hidWriter)
        {
            _statusLabel.Text = "Connecting...";
            _hidWriter = hidWriter;
            _waitResult = waitResult;
            if (device.Address > 0)
            {
                _existingMachine.Dock = DockStyle.Fill;
                _existingMachine.Visible = true;
                _newMachineLabel.Visible = false;
            }
            else
            {
                _newMachineLabel.Dock = DockStyle.Fill;
                _newMachineLabel.Visible = true;
                _existingMachine.Visible = false;
            }

            timer1.Enabled = true;

            if (waitResult.WaitOne(1000, false))
            {
                //return DialogResult.OK;
            }

            try
            {
                return base.ShowDialog(parentForm);
            }
            finally
            {
                timer1.Enabled = false;
            }
        }
開發者ID:nbclark,項目名稱:mobile-remote,代碼行數:34,代碼來源:WaitForConnection.cs

示例3: Start

        public void Start(WaitHandle waitHandle)
        {
            var client = new ResbitClient("http://localhost:55672", "guest", "guest");

            Console.WriteLine(client.AlivenessTest.Get(""));

            waitHandle.WaitOne();
        }
開發者ID:simoneb,項目名稱:Roger,代碼行數:8,代碼來源:AlivenessTest.cs

示例4: Start

        public void Start(WaitHandle waitHandle)
        {
            var client = new ResbitClient("http://localhost:55672", "guest", "guest");

            foreach (var property in (IDictionary<string, object>)client.WhoAmI.Get())
                Console.WriteLine(property.Key);

            waitHandle.WaitOne();
        }
開發者ID:simoneb,項目名稱:Roger,代碼行數:9,代碼來源:WhoAmI.cs

示例5: WaitOne

 public static void WaitOne(WaitHandle handle, int timeout = 60 * 1000)
 {
     bool ok = handle.WaitOne(timeout);
     if (!ok)
     {
         // timeout. Event not signaled in time. 
         throw new ApplicationException("Condition not reached within timeout.");
     }         
 }
開發者ID:jonkelling,項目名稱:azure-webjobs-sdk,代碼行數:9,代碼來源:TestHelpers.cs

示例6: Wait

 private static void Wait(Exception e, WaitHandle g)
 {
     if (!g.WaitOne(10000))
     {
         throw new Exception("timed out");
     }
     if (e != null)
     {
         throw e;
     }
 }
開發者ID:sopel,項目名稱:Salient.ReliableHttpClient,代碼行數:11,代碼來源:Program.cs

示例7: EnReadMemoryLogImpl

        /// <summary>
        /// 要求がある限りログを読み取ります。無限に列挙し続けます。
        /// </summary>
        /// <returns></returns>
        private static IEnumerable<FFXIVLog> EnReadMemoryLogImpl(WaitHandle wo)
        {
            if (wo.WaitOne(100)) yield break;
            yield return Internal(null, FFXILogMessageType.INTERNAL_START, "## FF14 ログ監視処理開始 ##");
            foreach (var ff14 in EnScanProcess()) {
                // プロセスを見つけられなかったら5秒待って再検索
                if (ff14 == null) {
            #if DEBUG
                    yield return Internal(null, FFXILogMessageType.INTERNAL_WAIT, "FF14プロセス検索:5秒待機");
            #endif
                    if (wo.WaitOne(5000)) yield break;
                    continue;
                }

                // ログ領域の検索。見つけられなかったら5秒まって再検索
                // 10回試行しても見つからなければ最初からやり直し
                yield return Internal(ff14, FFXILogMessageType.INTERNAL_FOUND14, "## FF14 プロセス発見、ログ領域検索開始 ##");
                FFXIVLogStatus reader = null;
                for (var i = 0; i < 10; i++) {
                    reader = ff14.SearchLogStatus();
                    if (reader != null) break;
            #if DEBUG
                    yield return Internal(ff14, FFXILogMessageType.INTERNAL_WAIT, "FF14ログ領域検索:5秒待機");
            #endif
                    if (wo.WaitOne(5000)) yield break;
                    continue;
                }
                if (reader == null) continue;

                yield return Internal(ff14, FFXILogMessageType.INTERNAL_FOUND_LOG, "## FF14 ログ領域発見、ログ列挙開始 ##");

                foreach (var log in reader.EnReadMemoryLog()) {
                    if (log == null) {
                        if (wo.WaitOne(10)) yield break;
                        continue;
                    }
                    yield return log;
                }
                yield return Internal(ff14, FFXILogMessageType.INTERNAL_LOST14, "## FF14 プロセスロスト ##");
            }
        }
開發者ID:pudwinkie,項目名稱:neith,代碼行數:45,代碼來源:XIVProcessWatch.cs

示例8: Start

        public void Start(WaitHandle waitHandle)
        {
            var connectionFactory = new DefaultConnectionFactory(Constants.HostName);

            PublisherConfirmsProvider.DeclareExchange(connectionFactory);
            var bus = new RogerBus(connectionFactory, new SimpleConsumerContainer(new PublisherConfirmsConsumer()));
            bus.Start();

            waitHandle.WaitOne();

            bus.Dispose();
        }
開發者ID:simoneb,項目名稱:Roger,代碼行數:12,代碼來源:Consumer.cs

示例9: Start

 public void Start(WaitHandle waitHandle)
 {
     using (var connection = CreateConnection())
     using (var model = connection.CreateModel())
     {
         while (!waitHandle.WaitOne(TimeSpan.FromMilliseconds(100)))
         {
             model.BasicPublish(Constants.FederationExchangeName, "Routing.Key", null, string.Format("Ciao from {0}", GetType().Name).Bytes());
             Console.WriteLine("Message published");
         }
     }
 }
開發者ID:simoneb,項目名稱:Roger,代碼行數:12,代碼來源:PublisherBase.cs

示例10: StartPublishing

        private void StartPublishing(IRabbitBus bus, WaitHandle waitHandle)
        {
            var counter = 0;

            while (!waitHandle.WaitOne(10))
            {
                bus.Publish(new PublisherConfirmsMessage {Counter = ++counter}, persistent: false);
                Console.WriteLine("Published message {0}", counter);
            }

            bus.Dispose();
        }
開發者ID:simoneb,項目名稱:Roger,代碼行數:12,代碼來源:Producer.cs

示例11: Run

        protected override void Run(WaitHandle shutdownHandle)
        {
            Console.WriteLine("StandardService, Service started. Waiting for exit event");

            while (!shutdownHandle.WaitOne(100))
            {
                //runs something every 100ms
            }
            

            Console.WriteLine("StandardService, Exiting");
        }
開發者ID:GitItInTheHub,項目名稱:Griffin.Framework,代碼行數:12,代碼來源:StandardService.cs

示例12: WaitOneOrTwoOrAllOthers

 public static int WaitOneOrTwoOrAllOthers(WaitHandle one, WaitHandle two, WaitHandle[] others)
 {
     CodeContract.Requires(one != null);
     CodeContract.Requires(two != null);
     CodeContract.Requires(others != null && others.Length > 1);
     var occurredEventIndex = WaitHandle.WaitTimeout;
     var eventSignaled = new ManualResetEvent(false);
     var waitOneThread = ThreadUtils.StartBackgroundThread(
         () =>
         {
             try
             {
                 one.WaitOne();
                 occurredEventIndex = 0;
             }
             finally
             {
                 eventSignaled.Set();
             }
         });
     var waitTwoThread = ThreadUtils.StartBackgroundThread(
         () =>
         {
             try
             {
                 two.WaitOne();
                 occurredEventIndex = 1;
             }
             finally
             {
                 eventSignaled.Set();
             }
         });
     var waitOthersThread = ThreadUtils.StartBackgroundThread(
         () =>
         {
             try
             {
                 WaitHandle.WaitAll(others);
                 occurredEventIndex = 2;
             }
             finally
             {
                 eventSignaled.Set();
             }
         });
     eventSignaled.WaitOne();
     waitOneThread.SafeAbort();
     waitTwoThread.SafeAbort();
     waitOthersThread.SafeAbort();
     return occurredEventIndex;
 }
開發者ID:nico-izo,項目名稱:KOIB,代碼行數:52,代碼來源:WaitHandleUtils.cs

示例13: Run

        public static void Run(WaitHandle exitHandle)
        {
            var serviceHost = new ServiceHost(new UtilWcfService());
            serviceHost.AddServiceEndpoint(typeof (IUtilWcfService), new NetTcpBinding(SecurityMode.None){TransferMode = TransferMode.Streamed}, "net.tcp://localhost:54321");

            Console.WriteLine("WCF SERVER: Open");
            serviceHost.Open();
            Console.WriteLine("WCF SERVER: Wait");
            exitHandle.WaitOne();
            Console.WriteLine("WCF SERVER: Close");
            serviceHost.Close();
            Console.WriteLine("WCF SERVER: Done");
        }
開發者ID:mtmk,項目名稱:csutil,代碼行數:13,代碼來源:UtilWcfService.cs

示例14: Start

        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
            using (var model = connection.CreateModel())
            {
                model.ExchangeDeclare(Constants.ExchangeName, ExchangeType.Topic, false, true, null);

                while (!waitHandle.WaitOne(TimeSpan.FromSeconds(5)))
                {
                    var routingKey = CreateRoutingKey();
                    model.BasicPublish(Constants.ExchangeName, routingKey, null, GetBody(routingKey));
                    Console.WriteLine("Published {0} message", routingKey);
                }
            }
        }
開發者ID:simoneb,項目名稱:Roger,代碼行數:15,代碼來源:Publisher.cs

示例15: Start

        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare("hello", false, false, false, null);
                Console.WriteLine("Waiting for messages...");

                var consumer = new EventingBasicConsumer();
                consumer.Received += ConsumerOnReceived;
                channel.BasicConsume(Constants.QueueName, true, consumer);

                waitHandle.WaitOne();
            }
        }
開發者ID:simoneb,項目名稱:Roger,代碼行數:15,代碼來源:Receiver.cs


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