コード例 #1
0
 private static void WriteLoop(CancellationToken token)
 {
     lock (writeQueue) {
         if (writeQueue.Count != 0)
         {
             WriteRequest request = writeQueue.Dequeue();
             request.Send();
         }
     }
     token.Sleep(maxWriteFrequency);
     if (writeQueue.Count == 0)
     {
         writeReady.WaitOne();
     }
 }
コード例 #2
0
        /// <summary>Adds a write request to the write queue.</summary>
        /// <param name="request">The request to write.</param>
        /// <returns>The position in the queue.</returns>

        /*internal static int QueueWriteRequest(WriteRequest request) {
         *      lock (writeQueue) {
         *              writeQueue.Enqueue(request);
         *              return writeQueue.Count - 1;
         *      }
         * }*/

        /// <summary>Adds a write request to the write queue.</summary>
        /// <param name="request">The request to write.</param>
        /// <returns>The position in the queue.</returns>
        internal static int QueueWriteRequest(Wiimote wiimote, byte[] buff)
        {
            WriteRequest request = new WriteRequest(wiimote, buff);

            if (!request.Send())
            {
                //Debug.WriteLine($"Failed to send: {request}");
            }
            return(0);

            /*lock (writeQueue) {
             *      writeQueue.Enqueue(new WriteRequest(wiimote, buff));
             *      writeReady.Set();
             *      return writeQueue.Count - 1;
             * }*/
        }