UsbUirt.Transmitter.TransmitAsync C# (CSharp) Method

TransmitAsync() public method

Transmits an IR code asynchronously.
public TransmitAsync ( string irCode, object userState = null, Emitter emitter = null, CodeFormat codeFormat = null, int repeatCount = null, int inactivityWaitTime = null ) : Task
irCode string The IR code to transmit.
userState object An optional user state object that will be passed to the /// TransmitCompleted event.
emitter Emitter The emitter to transmit the IR code with
codeFormat CodeFormat The format of the IR code.
repeatCount int Indicates how many iterations of the code should be /// sent (in the case of a 2-piece code, the first stream is sent once followed /// by the second stream sent repeatCount times).
inactivityWaitTime int Time in milliseconds since the last received /// IR activity to wait before sending an IR code. Normally, pass 0 for this parameter.
return Task
        public Task TransmitAsync(
            string irCode,
            object userState = null,
            Emitter? emitter = null,
            CodeFormat? codeFormat = null,
            int? repeatCount = null,
            int? inactivityWaitTime = null)
        {
            CheckDisposed();
            var task = Task.Factory
                .StartNew(() => TransmitInternal(irCode,
                    codeFormat,
                    repeatCount,
                   inactivityWaitTime,
                    emitter));
                task.ContinueWith(t =>
                {
                    var temp = TransmitCompleted;
                    if (null != temp)
                    {
                        temp(this, new TransmitCompletedEventArgs(t.Exception, userState));
                    }
                });
            return task;
        }

Usage Example

        private static void LearnAndTransmitACode()
        {
            using (var driver = new Driver())
            {
                Console.WriteLine(Driver.GetVersion(driver).ToString());

                Console.WriteLine("Receiving...");
                var receiver = new Receiver(driver);
                receiver.GenerateLegacyCodes = false;
                receiver.Received += OnReceive;

                var learner = new Learner(driver);
                learner.Learning += OnLearning;
                Console.WriteLine("Learning...");
                var result = learner.Learn();
                Console.WriteLine("Learned code: " + result);

                Console.WriteLine("Hit enter to Transmit");
                Console.ReadLine();
                var transmitter = new Transmitter(driver);
                transmitter.TransmitCompleted += OnTransmitComplete;
                transmitter.TransmitAsync(result, emitter: Emitter.Internal)
                    .ContinueWith(t => Console.WriteLine(t.Exception == null
                                        ? "Transmit Complete - from task"
                                        : t.Exception.ToString()));
            }
        }
All Usage Examples Of UsbUirt.Transmitter::TransmitAsync