当前位置: 首页>>代码示例>>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;未经允许,请勿转载。