Exemple #1
0
 /// <summary>Decodes all RTT text immediately</summary>
 /// <returns>Resulting decoded message</returns>
 public string FullDecodeNow()
 {
     lock (rttElementQueue)
     {
         message.KeyIntervalsEnabled = false;
         foreach (XmlElement rtt in rttElementQueue)
         {
             RealTimeText.DecodeRawRTT(rtt, message);
         }
         rttElementQueue.Clear();
         message.KeyIntervalsEnabled = true;
         return(message.Text);
     }
 }
Exemple #2
0
            /// <summary>Background decode thread</summary>
            private void DecodeThread()
            {
                XmlElement      rtt;
                bool            elementsFound   = false;
                int             interval        = 0;
                DelayCalculator delayCalculator = new DelayCalculator();

                while (true)
                {
                    lock (rttElementQueue)
                    {
                        if (!enableThread)
                        {
                            break;
                        }

                        elementsFound = (rttElementQueue.Count > 0);
                        if (elementsFound)
                        {
                            // Start the delay calculator on the moment of the first RTT element received into empty queue
                            if (!delayCalculator.IsRunning)
                            {
                                delayCalculator.Start();
                            }

                            // Loop to decode RTT elements
                            while (enableThread && (rttElementQueue.Count > 0))
                            {
                                rtt = rttElementQueue[0];
                                RealTimeText.DecodeRawRTT(rtt, message);
                                if (!rtt.HasChildNodes)
                                {
                                    rttElementQueue.RemoveAt(0);
                                }

                                if (message.CurrentKeyInterval != 0)
                                {
                                    interval = message.CurrentKeyInterval;
                                    break;
                                }
                            }
                        }
                        if (!enableThread)
                        {
                            break;
                        }
                    }

                    // (MUST be outside 'lock' section) Calls the user-defined event for one step of text decode
                    if (elementsFound && (TextUpdated != null))
                    {
                        TextUpdated(this);
                    }

                    if (interval > 0)
                    {
                        // Calculate the delay interval and then sleep for that interval if needed.
                        // IMPORTANT: This SAVES BATTERY on mobile devices! (avoids unnecessary processing)
                        interval = delayCalculator.GetCompensatedDelay(interval);
                        if (interval > 0)
                        {
                            Thread.Sleep(interval);
                        }
                        interval = 0;
                    }
                    else
                    {
                        // Zero interval. Stop the delay calculator, and suspend this thread until the next RTT element
                        // IMPORTANT: This also SAVES BATTERY on mobile devices! (turns off unnecessary timers when idling with no typing going on)
                        delayCalculator.Stop();
                        rttElementEvent.WaitOne(IDLE_THREAD_QUIT_INTERVAL);
                        rttElementEvent.Reset();

                        // Exit thread if we've waited long enough with no elements arrived. Thread will restart automatically.
                        // This saves system resources (and battery life on mobiles) if there's lots of chat windows.
                        lock (rttElementQueue)
                        {
                            if (rttElementQueue.Count == 0)
                            {
                                enableThread = false;
                                break;
                            }
                        }
                    }
                }
                Debug.Write("STOPPING rtt decoder thread\n");
            }