示例#1
0
        private void StartStream(TwitterContext context)
        {
            var stream = _streamTask;

            if (stream != null)
            {
                stream.Wait();
            }

            _streamTask = Task.Factory.StartNew
                          (
                () =>
            {
                if (_isStreamStarted)
                {
                    return;
                }

                if (_isStreamStarted)
                {
                    return;
                }

                _isStreamStarted = true;
                if (!context.TryInvokeAction(() => _stream.StartStream(_token, tweet => Trace.Write("."))))
                {
                    Trace.WriteLine(string.Format("An Exception occured : '{0}'",
                                                  context.LastActionTwitterException.TwitterWebExceptionErrorDescription));
                }

                _isStreamStarted = false;
                _streamTask      = null;
            }
                , TaskCreationOptions.LongRunning);
        }