UsbUirt.Controller.LearnAsyncCancel C# (CSharp) Method

LearnAsyncCancel() public method

Cancels a LearnAsync() operation that was passed the specified userState.
public LearnAsyncCancel ( object userState ) : bool
userState object The optional userState object passed to LearnAsync().
return bool
        public bool LearnAsyncCancel(object userState)
        {
            CheckDisposed();
            object learnStatesKey = null == userState ? this : userState;
            var learnState = _learnStates[learnStatesKey] as LearnState;
            if (null != learnState) {
                learnState.Abort();
                return true;
            }
            return false;
        }

Same methods

Controller::LearnAsyncCancel ( ) : void

Usage Example

Exemplo n.º 1
0
        private static void TestLearn(Controller mc, CodeFormat learnFormat, LearnCodeModifier learnCodeModifier)
        {
            learnCompletedEventArgs = null;
            Console.WriteLine("<Press x to abort Learn>");
            mc.Learning += new UsbUirt.Controller.LearningEventHandler(mc_Learning);
            mc.LearnCompleted += new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted);

            try
            {
                try
                {
                    mc.LearnAsync(learnFormat, learnCodeModifier, learnCompletedEventArgs);
                }
                catch(Exception ex)
                {
                    Console.WriteLine("*** ERROR calling LearnAsync! ***");
                    throw;
                }

                while (learnCompletedEventArgs == null)
                {
                    string s = Console.ReadLine();
                    if (s.Length != 0 && s[0] == 'x')
                    {
                        if (learnCompletedEventArgs == null)
                        {
                            Console.WriteLine("Calling LearnAsyncCancel...");
                            mc.LearnAsyncCancel(learnCompletedEventArgs);
                            Thread.Sleep(1000);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("<Press x to abort Learn>");
                    }
                }

                if (learnCompletedEventArgs != null &&
                    learnCompletedEventArgs.Cancelled == false &&
                    learnCompletedEventArgs.Error == null)
                {
                    irCode = learnCompletedEventArgs.Code;
                    Console.WriteLine("...Done...IRCode = {0}", irCode);
                    transmitFormat = learnFormat;
                }

            }
            finally
            {
                mc.Learning -= new UsbUirt.Controller.LearningEventHandler(mc_Learning);
                mc.LearnCompleted -= new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted);
            }
        }
All Usage Examples Of UsbUirt.Controller::LearnAsyncCancel