예제 #1
0
 protected virtual void OnResponseReady(HueResponseEventArgs e)
 {
     if (ResponseReady != null)
     {
         ResponseReady(this, e);
     }
 }
예제 #2
0
        private void StartConsumer()
        {
            if (_task == null)
            {
                _scheduleTicker.TimerStart();
                _task = Task.Factory.StartNew(async() =>
                {
                    try
                    {
                        Debug.WriteLine("starting consumer thread");
                        Debug.WriteLine("waiting for queue or kill task");
                        while (WaitHandle.WaitAny(_queueEvents) != 0)
                        {
                            Debug.WriteLine("queued item detected, waiting for ticker");
                            while (WaitHandle.WaitAny(_tickerEvents) != 0)
                            {
                                Debug.WriteLine("ticker detected");
                                QueueItem dequeueItem = _queue.DequeueSync();

                                if (dequeueItem != null)
                                {
                                    HueObjectBase rv = await LoginWrapperAsync(dequeueItem.Action);

                                    if (_syncItemQueueResponses.ContainsKey(dequeueItem.Path))
                                    {
                                        _syncItemQueueResponses[dequeueItem.Path] = rv;
                                    }
                                    else
                                    {
                                        _syncItemQueueResponses.Add(dequeueItem.Path, rv);
                                    }

                                    Debug.WriteLine(rv);
                                    var eventArgs = new HueResponseEventArgs {
                                        Response = rv, Path = dequeueItem.Path
                                    };
                                    OnResponseReady(eventArgs);
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Debug.WriteLine(exception.Message);
                        _task = null;
                    }

                    Debug.WriteLine("stopping consumer thread");
                });
            }
        }