Summary description for SyncLearnResults.
Inheritance: IDisposable
Ejemplo n.º 1
0
        /// <summary>
        ///     Learns an IR code synchronously.
        /// </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="timeout">The timeout after which to abort learning if it has not completed.</param>
        /// <returns>The IR code that was learned, or null if learning failed.</returns>
        public string Learn(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat,
                            uint forcedFrequency, TimeSpan timeout)
        {
            CheckDisposed();
            if (timeout < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeout", "timeout cannot be negative");
            }

            using (var results = new SyncLearnResults()) {
                LearnCompleted += ManagedWrapper_LearnCompleted;

                try {
                    LearnAsync(codeFormat, learnCodeFormat, forcedFrequency, results);
                    if (TimeSpan.Zero == timeout)
                    {
                        results.WaitEvent.WaitOne();
                        return(results.LearnCompletedEventArgs.Code);
                    }
                    else if (results.WaitEvent.WaitOne(timeout, false))
                    {
                        if (null != results.LearnCompletedEventArgs.Error)
                        {
                            throw results.LearnCompletedEventArgs.Error;
                        }
                        else if (results.LearnCompletedEventArgs.Cancelled)
                        {
                            return(null);
                        }
                        return(results.LearnCompletedEventArgs.Code);
                    }
                    else
                    {
                        LearnAsyncCancel(results);
                        return(null);
                    }
                }
                finally {
                    LearnCompleted -= ManagedWrapper_LearnCompleted;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Learns an IR code synchronously.
        /// </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="timeout">The timeout after which to abort learning if it has not completed.</param>
        /// <returns>The IR code that was learned, or null if learning failed.</returns>
        public string Learn(CodeFormat codeFormat, LearnCodeModifier learnCodeFormat, 
			uint forcedFrequency, TimeSpan timeout)
        {
            CheckDisposed();
            if (timeout < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeout", "timeout cannot be negative");
            }

            using (SyncLearnResults results = new SyncLearnResults())
            {
                this.LearnCompleted += new LearnCompletedEventHandler(ManagedWrapper_LearnCompleted);

                try
                {
                    LearnAsync(codeFormat, learnCodeFormat, forcedFrequency, results);
                    if (TimeSpan.Zero == timeout)
                    {
                        results.WaitEvent.WaitOne();
                        return results.LearnCompletedEventArgs.Code;
                    }
                    else if (results.WaitEvent.WaitOne(timeout, false))
                    {
                        if (null != results.LearnCompletedEventArgs.Error)
                        {
                            throw results.LearnCompletedEventArgs.Error;
                        }
                        else if (false != results.LearnCompletedEventArgs.Cancelled)
                        {
                            return null;
                        }
                        return results.LearnCompletedEventArgs.Code;
                    }
                    else
                    {
                        LearnAsyncCancel(results);
                        return null;
                    }
                }
                finally
                {
                    this.LearnCompleted -= new LearnCompletedEventHandler(ManagedWrapper_LearnCompleted);
                }
            }
        }