WaitOne() public method

public WaitOne ( ) : bool
return bool
コード例 #1
0
        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;
            }
        }
コード例 #2
0
 private void OnConnectPeer()
 {
     Console.WriteLine("Connecting to Peer @ {0}:{1}", PeerHost, PeerPort);
     ConnectedToPeer = false;
     for (var i = 0; i < MAX_Connect_Attempts && !ConnectedToPeer; i++)
     {
         Console.Write("C");
         Peer = new TcpClient();
         Task ar = Peer.ConnectAsync(PeerHost, PeerPort);
         System.Threading.WaitHandle wh = ((IAsyncResult)ar).AsyncWaitHandle;
         bool signaled = wh.WaitOne(TimeSpan.FromMilliseconds(1200));
         if (!signaled || !Peer.Connected)
         {
             Console.Write("x");
         }
         else
         {
             ConnectedToPeer = true;
         }
     }
     if (ConnectedToPeer)
     {
         Console.WriteLine("\nConnected to {0}:{1}, start sending ping...", PeerHost, PeerPort);
         stateMachine.FireAsync(Trigger.ConnectedToPeer);
     }
     else
     {
         Console.WriteLine(" - couldn't reach to peer");
         stateMachine.FireAsync(Trigger.FailedToPeer);
     }
 }
コード例 #3
0
ファイル: Concurrency.cs プロジェクト: davidd2k/OctoDB
        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;
        }
コード例 #4
0
ファイル: AlivenessTest.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            var client = new ResbitClient("http://localhost:55672", "guest", "guest");

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

            waitHandle.WaitOne();
        }
コード例 #5
0
ファイル: WhoAmI.cs プロジェクト: simoneb/Roger
        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();
        }
コード例 #6
0
 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.");
     }         
 }
コード例 #7
0
 private static void Wait(Exception e, WaitHandle g)
 {
     if (!g.WaitOne(10000))
     {
         throw new Exception("timed out");
     }
     if (e != null)
     {
         throw e;
     }
 }
コード例 #8
0
ファイル: Interop.Manual.cs プロジェクト: rdlaitila/corert
        internal static void Sleep(uint milliseconds)
        {
#if CORECLR
            System.Threading.Thread.Sleep(0);
#else
            if (milliseconds == 0)
                System.Threading.SpinWait.Yield();
            else
                s_sleepHandle.WaitOne((int)milliseconds);
#endif
        }
コード例 #9
0
 static internal void Sleep(uint milliseconds)
 {
     if (milliseconds == 0)
     {
         System.Threading.SpinWait.Yield();
     }
     else
     {
         s_sleepHandle.WaitOne((int)milliseconds);
     }
 }
コード例 #10
0
ファイル: XIVProcessWatch.cs プロジェクト: pudwinkie/neith
        /// <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 プロセスロスト ##");
            }
        }
コード例 #11
0
ファイル: Consumer.cs プロジェクト: simoneb/Roger
        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();
        }
コード例 #12
0
ファイル: PublisherBase.cs プロジェクト: simoneb/Roger
 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");
         }
     }
 }
コード例 #13
0
        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");
        }
コード例 #14
0
ファイル: Producer.cs プロジェクト: simoneb/Roger
        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();
        }
コード例 #15
0
ファイル: WaitHandleUtils.cs プロジェクト: nico-izo/KOIB
 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;
 }
コード例 #16
0
ファイル: UtilWcfService.cs プロジェクト: mtmk/csutil
        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");
        }
コード例 #17
0
ファイル: Receiver.cs プロジェクト: simoneb/Roger
        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();
            }
        }
コード例 #18
0
ファイル: Publisher.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
            using (var model = connection.CreateModel())
            {
                model.ExchangeDeclare(Constants.ExchangeName, ExchangeType.Direct, false, true, null);

                while (!waitHandle.WaitOne(TimeSpan.FromSeconds(5)))
                {
                    var severity = Severity.Random();
                    model.BasicPublish(Constants.ExchangeName, severity, null, GetBody(severity));
                    Console.WriteLine("Published {0} message", severity);
                }
            }
        }
コード例 #19
0
ファイル: Publisher.cs プロジェクト: simoneb/Roger
        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);
                }
            }
        }
コード例 #20
0
ファイル: Publisher.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(Constants.ExchangeName, ExchangeType.Fanout, false, true, null);

                while (!waitHandle.WaitOne(TimeSpan.FromSeconds(5)))
                {
                    channel.BasicPublish(Constants.ExchangeName, "", null,
                                         Encoding.UTF8.GetBytes("Ciao " + DateTime.Now.ToLongTimeString()));
                    Console.WriteLine("Message published");
                }
            }
        }
コード例 #21
0
ファイル: FibonacciService.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
            using(var channel = connection.CreateModel())
            {
                channel.QueueDeclare(Constants.RpcQueueName, false, false, true, null);
                channel.BasicQos(0, 1, false);

                var consumer = new EventingBasicConsumer {Model = channel};
                consumer.Received += ConsumerOnReceived;
                channel.BasicConsume(Constants.RpcQueueName, false, consumer);

                waitHandle.WaitOne();
            }
        }
コード例 #22
0
        private static void Unsignal(WaitHandle wh)
        {
            var eventWh = wh as ManualResetEvent;
            var mutexWh = wh as Mutex;
            var semaphoreWh = wh as Semaphore;

            if (eventWh != null)
            {
                eventWh.Reset();
            }
            else
            {
                Assert.True(mutexWh != null || semaphoreWh != null);
                Assert.True(wh.WaitOne(0));
            }
        }
コード例 #23
0
ファイル: WaitLoop.cs プロジェクト: robindegen/MIEngine
        /// <summary>
        /// Waits on the specified handle. This method should be called only once.
        /// </summary>
        /// <param name="launchCompleteHandle">[Required] handle to wait on</param>
        /// <param name="cancellationSource">[Required] Object to signal cancellation if cancellation is requested</param>
        /// <returns>true if we were able to successfully wait, false if we failed to wait and should fall back to the CLR provided wait function</returns>
        /// <exception cref="FileNotFoundException">Thrown by the JIT if Visual Studio is not installed</exception>
        public void Wait(WaitHandle launchCompleteHandle, CancellationTokenSource cancellationSource)
        {
            if (_vsWaitLoop != null)
            {
                _vsWaitLoop.Wait(launchCompleteHandle, cancellationSource);

                lock (_progressLock)
                {
                    _vsWaitLoop = null;
                }
            }
            else
            {
                launchCompleteHandle.WaitOne(); // For glass, fall back to waiting using the .NET Framework APIs
            }
        }
コード例 #24
0
ファイル: FibonacciClient.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
             using (var channel = connection.CreateModel())
             {
                 channel.QueueDeclare(Constants.RpcQueueName, false, false, true, null);
                 var queueName = channel.QueueDeclare("", false, true, true, null);

                 var consumer = new EventingBasicConsumer {Model = channel};
                 consumer.Received += ConsumerOnReceived;

                 channel.BasicConsume(queueName, true, consumer);

                 while (!waitHandle.WaitOne(TimeSpan.FromSeconds(5)))
                     CallService(channel, queueName);
             }
        }
コード例 #25
0
ファイル: SubscriberBase.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            using (var connection = CreateConnection())
            using (var model = connection.CreateModel())
            {
                var queue = model.QueueDeclare("", false, true, false, null);

                model.QueueBind(queue, Constants.FederationExchangeName, "Routing.Key");

                var consumer = new EventingBasicConsumer { Model = model };

                consumer.Received += ConsumerOnReceived;

                model.BasicConsume(queue, true, consumer);

                waitHandle.WaitOne();
            }
        }
コード例 #26
0
ファイル: Consumer.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(Constants.ExchangeName, ExchangeType.Topic, false, true, null);
                var queue = channel.QueueDeclare("", false, true, true, null);

                channel.QueueBind(queue, Constants.ExchangeName, bindingKey);

                var consumer = new EventingBasicConsumer { Model = channel };

                consumer.Received += ConsumerOnReceived;

                channel.BasicConsume(queue, true, consumer);

                waitHandle.WaitOne();
            }
        }
コード例 #27
0
ファイル: NewTask.cs プロジェクト: simoneb/Roger
        public void Start(WaitHandle waitHandle)
        {
            using (var connection = Helpers.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(Constants.QueueName, true, false, false, null);

                var basicProperties = channel.CreateBasicProperties();
                basicProperties.DeliveryMode = 2;

                while (!waitHandle.WaitOne(TimeSpan.FromSeconds(5)))
                {
                    channel.BasicPublish("",
                                         Constants.QueueName,
                                         basicProperties,
                                         Encoding.UTF8.GetBytes("Ciao " + DateTime.Now.ToLongTimeString()));
                    Console.WriteLine("Message published");
                }
            }
        }
コード例 #28
0
ファイル: AsyncFactory.cs プロジェクト: jerkka/Olan
        /// <summary>
        /// Wraps a <see cref="WaitHandle"/> with a <see cref="Task{Boolean}"/>. If the <see cref="WaitHandle"/> is signalled, the returned task is completed with a <c>true</c> result. If the observation times out, the returned task is completed with a <c>false</c> result. If the observation is cancelled, the returned task is cancelled. If the handle is already signalled, the timeout is zero, or the cancellation token is already cancelled, then this method acts synchronously.
        /// </summary>
        /// <param name="handle">The <see cref="WaitHandle"/> to observe.</param>
        /// <param name="timeout">The timeout after which the <see cref="WaitHandle"/> is no longer observed.</param>
        /// <param name="token">The cancellation token that cancels observing the <see cref="WaitHandle"/>.</param>
        public static Task<bool> FromWaitHandle(WaitHandle handle, TimeSpan timeout, CancellationToken token)
        {
            // Handle synchronous cases.
            var alreadySignalled = handle.WaitOne(0);
            if (alreadySignalled) {
                return TaskConstants.BooleanTrue;
            }
            if (timeout == TimeSpan.Zero) {
                return TaskConstants.BooleanFalse;
            }
            if (token.IsCancellationRequested) {
                return TaskConstants<bool>.Canceled;
            }

            // Register all asynchronous cases.
            var tcs = new TaskCompletionSource<bool>();
            var threadPoolRegistration = ThreadPoolEnlightenment.RegisterWaitForSingleObject(handle, (state, timedOut) => ((TaskCompletionSource<bool>)state).TrySetResult(!timedOut), tcs, timeout);
            var tokenRegistration = token.Register(state => ((TaskCompletionSource<bool>)state).TrySetCanceled(), tcs, false);
            tcs.Task.ContinueWith(_ => {
                threadPoolRegistration.Dispose();
                tokenRegistration.Dispose();
            }, TaskScheduler.Default);
            return tcs.Task;
        }
コード例 #29
0
ファイル: Retry.cs プロジェクト: dougrathbone/mbunit-v3
            public void Until(WaitHandle waitHandle)
            {
                if (waitHandle == null)
                    throw new ArgumentNullException("waitHandle");

                Run(() => waitHandle.WaitOne(0, false));
            }
コード例 #30
0
 internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext)
 {
     return waitHandle.WaitOne(millisecondsTimeout);
 }
コード例 #31
0
        public static bool WaitOne(WaitHandle waitHandle, TimeSpan timeout, bool exitSync)
        {
            if (timeout == TimeSpan.MaxValue)
            {
                waitHandle.WaitOne();
                return true;
            }
            else
            {
                TimeSpan maxWait = TimeSpan.FromMilliseconds(Int32.MaxValue);

                while (timeout > maxWait)
                {
                    bool signaled = waitHandle.WaitOne(maxWait, exitSync);

                    if (signaled)
                    {
                        return true;
                    }

                    timeout -= maxWait;
                }

                return waitHandle.WaitOne(timeout, exitSync);
            }
        }
コード例 #32
0
ファイル: TimeoutHelper.cs プロジェクト: modulexcite/IL2JS
 public static bool WaitOne(WaitHandle waitHandle, TimeSpan timeout)
 {
     ThrowIfNegativeArgument(timeout);
     if (timeout == TimeSpan.MaxValue)
     {
         waitHandle.WaitOne();
         return true;
     }
     else
     {
         return waitHandle.WaitOne(timeout, false);
     }
 }
コード例 #33
0
 private static void DisConnection(Connection connection, WaitHandle modeChanged)
 {
     connection.Disconnect();
     modeChanged.WaitOne();
     Assert.IsTrue(connection.Mode == ConnectMode.None, "Mode is: " + connection.Mode);
 }
コード例 #34
0
 public static bool WaitOne(this WaitHandle handle, TimeSpan timeout)
 {
     return(handle.WaitOne(ToTimeoutMilliseconds(timeout), false));
 }
コード例 #35
0
 public static bool WaitOne(this WaitHandle handle, int millisecondsTimeout)
 => handle.WaitOne(millisecondsTimeout, false);