WaitOne() public method

public WaitOne ( ) : bool
return bool
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        public void Start(WaitHandle waitHandle)
        {
            var client = new ResbitClient("http://localhost:55672", "guest", "guest");

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

            waitHandle.WaitOne();
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 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.");
     }         
 }
Ejemplo n.º 7
0
 private static void Wait(Exception e, WaitHandle g)
 {
     if (!g.WaitOne(10000))
     {
         throw new Exception("timed out");
     }
     if (e != null)
     {
         throw e;
     }
 }
Ejemplo n.º 8
0
        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
        }
Ejemplo n.º 9
0
 static internal void Sleep(uint milliseconds)
 {
     if (milliseconds == 0)
     {
         System.Threading.SpinWait.Yield();
     }
     else
     {
         s_sleepHandle.WaitOne((int)milliseconds);
     }
 }
Ejemplo n.º 10
0
        /// <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 プロセスロスト ##");
            }
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
 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");
         }
     }
 }
        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");
        }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
        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");
        }
Ejemplo n.º 17
0
        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();
            }
        }
Ejemplo n.º 18
0
        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);
                }
            }
        }
Ejemplo n.º 19
0
        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);
                }
            }
        }
Ejemplo n.º 20
0
        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");
                }
            }
        }
Ejemplo n.º 21
0
        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();
            }
        }
        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));
            }
        }
Ejemplo n.º 23
0
        /// <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
            }
        }
Ejemplo n.º 24
0
        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);
             }
        }
Ejemplo n.º 25
0
        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();
            }
        }
Ejemplo n.º 26
0
        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();
            }
        }
Ejemplo n.º 27
0
        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");
                }
            }
        }
Ejemplo n.º 28
0
        /// <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;
        }
Ejemplo n.º 29
0
            public void Until(WaitHandle waitHandle)
            {
                if (waitHandle == null)
                    throw new ArgumentNullException("waitHandle");

                Run(() => waitHandle.WaitOne(0, false));
            }
Ejemplo n.º 30
0
 internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext)
 {
     return waitHandle.WaitOne(millisecondsTimeout);
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 32
0
 public static bool WaitOne(WaitHandle waitHandle, TimeSpan timeout)
 {
     ThrowIfNegativeArgument(timeout);
     if (timeout == TimeSpan.MaxValue)
     {
         waitHandle.WaitOne();
         return true;
     }
     else
     {
         return waitHandle.WaitOne(timeout, false);
     }
 }
Ejemplo n.º 33
0
 private static void DisConnection(Connection connection, WaitHandle modeChanged)
 {
     connection.Disconnect();
     modeChanged.WaitOne();
     Assert.IsTrue(connection.Mode == ConnectMode.None, "Mode is: " + connection.Mode);
 }
Ejemplo n.º 34
0
 public static bool WaitOne(this WaitHandle handle, TimeSpan timeout)
 {
     return(handle.WaitOne(ToTimeoutMilliseconds(timeout), false));
 }
Ejemplo n.º 35
0
 public static bool WaitOne(this WaitHandle handle, int millisecondsTimeout)
 => handle.WaitOne(millisecondsTimeout, false);