Esempio n. 1
0
        /// <summary>
        /// Parallel decompress
        /// </summary>
        protected void DecompressParallel()
        {
            //Create thread pool
            var tPool = new ThreadsManager(base._totalThreads);

            try
            {
                Thread readThread = new Thread(this.ReadFromFile);
                readThread.Start();
                Thread writeThread = new Thread(this.WriteToFile);
                writeThread.Start();

                for (int i = 0; i < base._totalThreads; i++)
                {
                    tPool.AddThread(DataProcessing);
                }
                tPool.StartThreads();

                tPool.WaitAll();

                IsWorkComplete = true;

                writeThread.Join();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                tPool.Dispose();
            }
        }
Esempio n. 2
0
        public void L2Start()
        {
            try
            {
                L2TxThread      = new Thread(new ThreadStart(TxThreadProcess));
                L2TxThread.Name = "L2 - TX Thread" + cfg.GetName();

                L1Handler.Open();

                AddPkg2TxQueue.Reset();
                TxQueue.Clear();
                ThMan.AddThread(L2TxThread.Name, L2TxThread);
                L2TxThread.Start();
            }
            catch (System.Exception ex)
            {
                if (L1Handler.IsConnected())
                {
                    L1Handler.Close();
                }
                Thread t = ThMan.RemoveThread(L2TxThread.Name);

                if (t != null)
                {
                    t.Abort();
                    t = null;
                }

                throw ex;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// open connection with given config
        /// </summary>
        public virtual void Open()
        {
            try
            {
                if (seialPort != null)
                {
                    seialPort.Close();
                }
                seialPort          = new SerialPort();
                seialPort.PortName = config.PortName;
                seialPort.BaudRate = config.BaudRate;
                seialPort.DataBits = config.DataBit;
                seialPort.Parity   = config.parity;
                seialPort.StopBits = config.stopbit;

                // Set the read/write timeouts
                //TODO: get grom config, do not hardcode
                seialPort.ReadBufferSize  = 4096;
                seialPort.WriteBufferSize = 4096;
                seialPort.ReadTimeout     = 1000;
                seialPort.WriteTimeout    = 1500;

                // set handler
                seialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
                seialPort.Open();
                seialPort.DiscardInBuffer();
                isConnected = true;

                ThreadCom      = new Thread(new ThreadStart(NotifyReceiveMessage));
                ThreadCom.Name = "Communications - Receive message. L1 " + config.GetName();

                ThMan.AddThread(ThreadCom.Name, ThreadCom);

                ThreadCom.Start();
            }
            catch (System.Exception ex)
            {
                isConnected = false;
                throw ex;
            }
        }
Esempio n. 4
0
        public void Open()
        {
            try
            {
                if(clientSocket.Connected)
                {
                    Close();
                }

	            clientSocket.Connect(new IPEndPoint(IPAddress.Parse(config.IPAddress), config.IPPort));
	            ThreadCom = new Thread(new ThreadStart(NotifyReceiveMessage));
	            ThreadCom.Name = "Communications - Receive message";
	
	            ThMan.AddThread(ThreadCom.Name, ThreadCom);
	
	            ThreadCom.Start();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Parallel compressing
        /// </summary>
        protected void CompressParallel()
        {
            //Create pool of threads
            var tPool = new ThreadsManager(base._totalThreads);

            try
            {
                //Thread for reading
                Thread readThread = new Thread(this.ReadFromFile);
                readThread.Start();
                //Thread for writing
                Thread writeThread = new Thread(this.WriteToFile);
                writeThread.Start();

                //Add threads
                for (int i = 0; i < base._totalThreads; i++)
                {
                    tPool.AddThread(DataProcessing);
                }

                //Start threads
                tPool.StartThreads();

                //Waiting
                tPool.WaitAll();

                IsWorkComplete = true;

                //Wait finish write
                writeThread.Join();
            }
            finally
            {
                tPool.Dispose();
            }
        }