Summary description for LearnState.
상속: IDisposable
예제 #1
0
        /// <summary>
        ///     Learns an IR code asynchronously.
        /// </summary>
        /// <param name="codeFormat">The format of the IR code to use in learning.</param>
        /// <param name="learnCodeFormat">The modifier used for the code format.</param>
        /// <param name="forcedFrequency">The frequency to use in learning.</param>
        /// <param name="userState">
        ///     An optional user state object that will be passed to the
        ///     Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel().
        /// </param>
        public void LearnAsync(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat,
                               uint forcedFrequency, object userState)
        {
            CheckDisposed();
            if (LearnCodeModifier.ForceFrequency == learnCodeFormat)
            {
                if (0 == forcedFrequency)
                {
                    throw new ArgumentException("forcedFrequency", "forcedFrequency must be specified when using LearnCodeModifier.ForceFrequency");
                }
            }
            else
            {
                if (0 != forcedFrequency)
                {
                    throw new ArgumentException("forcedFrequency", "forcedFrequency can only be specified when using LearnCodeModifier.ForceFrequency");
                }
            }

            object learnStatesKey = null == userState ? this : userState;
            var    learnState     = new LearnState(codeFormat, learnCodeFormat, forcedFrequency, userState);

            _learnStates[learnStatesKey] = learnState;

            if (false == ThreadPool.QueueUserWorkItem(DoLearn, learnState))
            {
                throw new ApplicationException("Unable to QueueUserWorkItem");
            }
        }
예제 #2
0
        /// <summary>
        /// Learns an IR code asynchronously.
        /// </summary>
        /// <param name="codeFormat">The format of the IR code to use in learning.</param>
        /// <param name="learnCodeFormat">The modifier used for the code format.</param>
        /// <param name="forcedFrequency">The frequency to use in learning.</param>
        /// <param name="userState">An optional user state object that will be passed to the 
        /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel().</param>
        public void LearnAsync(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat,
			uint forcedFrequency, object userState)
        {
            CheckDisposed();
            if (LearnCodeModifier.ForceFrequency == learnCodeFormat)
            {
                if (0 == forcedFrequency)
                {
                    throw new ArgumentException("forcedFrequency", "forcedFrequency must be specified when using LearnCodeModifier.ForceFrequency");
                }
            }
            else
            {
                if (0 != forcedFrequency)
                {
                    throw new ArgumentException("forcedFrequency", "forcedFrequency can only be specified when using LearnCodeModifier.ForceFrequency");
                }
            }

            object learnStatesKey = null == userState ? this : userState;
            LearnState learnState = new LearnState(codeFormat, learnCodeFormat, forcedFrequency, userState);
            _learnStates[learnStatesKey] = learnState;

            if (false == ThreadPool.QueueUserWorkItem(new WaitCallback(DoLearn), learnState))
            {
                throw new ApplicationException("Unable to QueueUserWorkItem");
            }
        }
        /// <summary>
        /// Learns an IR code asynchronously.
        /// </summary>
        /// <param name="codeFormat">The format of the IR code to use in learning.</param>
        /// <param name="learnCodeModifier">The modifier used for the code format.</param>
        /// <param name="forcedFrequency">The frequency to use in learning.</param>
        /// <param name="userState">An optional user state object that will be passed to the 
        /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel().</param>
        public Task<string> LearnAsync(
            CodeFormat? codeFormat = null,
            LearnCodeModifier? learnCodeModifier = null,
            uint? forcedFrequency = null,
            object userState = null)
        {
            CheckDisposed();
            if (learnCodeModifier == LearnCodeModifier.ForceFrequency)
            {
                if (forcedFrequency == 0)
                {
                    throw new ArgumentException("forcedFrequency must be specified when using LearnCodeModifier.ForceFrequency",
                        "forcedFrequency");
                }
            }
            else
            {
                if (forcedFrequency != null && forcedFrequency != 0)
                {
                    throw new ArgumentException("forcedFrequency can only be specified when using LearnCodeModifier.ForceFrequency",
                        "forcedFrequency");
                }
            }

            object learnStatesKey = userState ?? this;
            var cancellationSource = new CancellationTokenSource();
            var learnState = new LearnState(
                    codeFormat ?? _defaultLearnCodeFormat,
                    learnCodeModifier ?? _defaultLearnCodeModifier,
                    cancellationSource,
                    forcedFrequency ?? 0,
                    userState);
            _learnStates[learnStatesKey] = learnState;

            var learnTask = Task<string>.Factory.StartNew(LearnInternal, learnState, cancellationSource.Token);
            learnTask.ContinueWith(t =>
            {
                try
                {
                    var temp = LearnCompleted;
                    if (temp != null)
                    {
                        temp(this,
                            new LearnCompletedEventArgs(t.Exception,
                                learnState.WasAborted,
                                t.Result,
                                learnState.UserState));
                    }
                }
                finally
                {
                    learnState.Dispose();
                    learnStatesKey = null == learnState.UserState ? this : t.AsyncState;
                    _learnStates[learnStatesKey] = null;
                }
            });

            return learnTask;
        }
예제 #4
0
        /// <summary>
        /// Learns an IR code asynchronously.
        /// </summary>
        /// <param name="codeFormat">The format of the IR code to use in learning.</param>
        /// <param name="learnCodeModifier">The modifier used for the code format.</param>
        /// <param name="forcedFrequency">The frequency to use in learning.</param>
        /// <param name="userState">An optional user state object that will be passed to the
        /// Learning and LearnCompleted events and which can be used when calling LearnAsyncCancel().</param>
        public Task <string> LearnAsync(
            CodeFormat?codeFormat = null,
            LearnCodeModifier?learnCodeModifier = null,
            uint?forcedFrequency = null,
            object userState     = null)
        {
            CheckDisposed();
            if (learnCodeModifier == LearnCodeModifier.ForceFrequency)
            {
                if (forcedFrequency == 0)
                {
                    throw new ArgumentException("forcedFrequency must be specified when using LearnCodeModifier.ForceFrequency",
                                                "forcedFrequency");
                }
            }
            else
            {
                if (forcedFrequency != null && forcedFrequency != 0)
                {
                    throw new ArgumentException("forcedFrequency can only be specified when using LearnCodeModifier.ForceFrequency",
                                                "forcedFrequency");
                }
            }

            object learnStatesKey     = userState ?? this;
            var    cancellationSource = new CancellationTokenSource();
            var    learnState         = new LearnState(
                codeFormat ?? _defaultLearnCodeFormat,
                learnCodeModifier ?? _defaultLearnCodeModifier,
                cancellationSource,
                forcedFrequency ?? 0,
                userState);

            _learnStates[learnStatesKey] = learnState;

            var learnTask = Task <string> .Factory.StartNew(LearnInternal, learnState, cancellationSource.Token);

            learnTask.ContinueWith(t =>
            {
                try
                {
                    var temp = LearnCompleted;
                    if (temp != null)
                    {
                        temp(this,
                             new LearnCompletedEventArgs(t.Exception,
                                                         learnState.WasAborted,
                                                         t.Result,
                                                         learnState.UserState));
                    }
                }
                finally
                {
                    learnState.Dispose();
                    learnStatesKey = null == learnState.UserState ? this : t.AsyncState;
                    _learnStates[learnStatesKey] = null;
                }
            });

            return(learnTask);
        }