예제 #1
0
 protected virtual bool AssyncWrite(AssyncIOEventArgs ioArgs)
 {
     if (ioArgs == null)
     {
         return(false);
     }
     //
     return(true);
 }
예제 #2
0
        void m_bgwAssync_DoWork(object sender, DoWorkEventArgs e)
        {
            m_bgwEnable = true;
            AssyncIOEventArgs ioArgs = null;

            while (m_bgwEnable)
            {
                if (m_bgwAssync.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                //
                if (!m_isInit)
                {
                    Thread.Sleep(10);
                    continue;
                }
                //
                CheckConnection();
                //
                if ((m_assyncIOqueue.Count <= 0))
                {                 // очередь пуста
                    Thread.Sleep(10);
                    continue;
                }
                // В очереди есть данные
                ioArgs = m_assyncIOqueue.Dequeue();
                if (ioArgs == null)
                {
                    continue;
                }
                //
                lock (m_syncObj)
                {
                    switch (ioArgs.IoType)
                    {
                    case IOType.Undefined:
                        break;

                    case IOType.Read:
                        if (ioArgs.Count <= 0)
                        {
                            break;
                        }
                        //
                        if (!CheckReaderIsOpen())
                        {
                            break;
                        }
                        //
                        AssyncRead(ioArgs);
                        Thread.Sleep(5);
                        //
                        break;

                    case IOType.Write:
                        if (ioArgs.Buf == null)
                        {
                            break;
                        }
                        //
                        if (!CheckWriterIsOpen())
                        {
                            break;
                        }
                        //
                        AssyncWrite(ioArgs);
                        Thread.Sleep(5);
                        //
                        break;

                    default:
                        break;
                    }
                }
            }
        }