Beispiel #1
0
 protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
 {
     if (myWorkState)
     {
         AiProtocol aiProtocol = new AiProtocol()
         {
             CaseNo = GateWaySetting.CaseNo, APISetting = APISetting
         };
         AbsProtocols.Add(aiProtocol);
         StateProtocol stateProtocol = new StateProtocol()
         {
             CaseNo = GateWaySetting.CaseNo, APISetting = APISetting
         };
         AbsProtocols.Add(stateProtocol);
         ReadThread = new Thread(Analysis);
         ReadThread.Start();
     }
     else
     {
         if (ReadThread != null)
         {
             ReadThread.Abort();
         }
     }
 }
Beispiel #2
0
        private void Read()
        {
            try
            {
                StreamReader sReader = new StreamReader(Client.GetStream());

                string msg = "";

                while (true)
                {
                    msg = sReader.ReadLine();

                    Console.WriteLine("{0}", msg);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Client?.Close();
                ReadThread.Abort();
            }
        }
Beispiel #3
0
        // null-safe & exception-safe: 2019-1-8
        private bool EndListen()
        {
            // catch null here.
            if (ReadThread == null)
            {
                Debugger.Log("ReadThread is null.", Debugger.LogLevel.WARN);
                return(false);
            }

            // catch other exceptions here.
            try
            {
                ReadThread.Abort();
                ReadThread = null;

                Debugger.Log("Successfully finished listening.", Debugger.LogLevel.INFO);

                Listening = false;
                return(true);
            }
            catch (Exception e)
            {
                Debugger.Log("Exception while aborting thread: \n" + e.ToString(), Debugger.LogLevel.ERROR);
                return(false);
            }
        }
Beispiel #4
0
 public void Cancel()
 {
     ReaderRunning = false;
     ReadThread.Abort();
     if (OscPacketIO.IsOpen())
     {
         OscPacketIO.Close();
     }
 }
Beispiel #5
0
        public void Close()
        {
            try
            {
                Console.WriteLine($"Goodbye {Username}!");

                TcpClient.Client.Close();
                TcpClient.Close();
                Program.Server.LeaveRoom(Username, Roomname);
                Program.Server.RemoveClient(Username);
                ReadThread.Abort();
            }
            catch (Exception e) {}
        }
Beispiel #6
0
        /**
         * Clear socket and threads
         */
        private void Clear()
        {
            if (ReadThread.IsAlive)
            {
                ReadThread.Abort();
            }

            if (WriteThread.IsAlive)
            {
                WriteThread.Abort();
            }

            Socket.Close();
        }
Beispiel #7
0
 protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
 {
     if (myWorkState)
     {
         ReadThread = new Thread(SqlRecord);
         ReadThread.Start();
     }
     else
     {
         if (ReadThread != null)
         {
             ReadThread.Abort();
         }
     }
 }
Beispiel #8
0
 private void StopThreads()
 {
     lock (this)
     {
         if (ReadThread != null)
         {
             ReadThread.Abort();
             ReadThread = null;
         }
         if (ReadTriggerThread != null)
         {
             ReadTriggerThread.Abort();
             ReadTriggerThread = null;
         }
     }
 }
Beispiel #9
0
 protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
 {
     if (myWorkState)
     {
         APIMethod.APISetting = APISetting;
         ReadThread           = new Thread(Analysis);
         ReadThread.Start();
     }
     else
     {
         if (ReadThread != null)
         {
             ReadThread.Abort();
         }
     }
 }
Beispiel #10
0
        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }


            if (ReadThread != null && ReadThread.IsAlive)
            {
                ThreadActive = false;
                ReadThread.Join(50);
                ReadThread.Abort();
            }

            if (ShmemChannel != null)
            {
                ShmemChannel.Unregister();
            }

            base.Dispose(disposing);
        }
Beispiel #11
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     ReadThread.Abort();
     SaveOptions();
     LogLine("Program terminated");
 }
Beispiel #12
0
        protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
        {
            if (myWorkState)
            {
                foreach (var item in ElectricConfigs)
                {
                    ElectricEnumType = (ElectricEnumType)item.ElectricEnumType;
                    switch (ElectricEnumType)
                    {
                    case ElectricEnumType.PA310:
                    {
                        PA310Protocol protocol = new PA310Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.HC660:
                    {
                        HC6600Protocol protocol = new HC6600Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.CPM6:
                    {
                        CPM6Protocol protocol = new CPM6Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.PA60:
                    {
                        PA60Protocol protocol = new PA60Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.ABBM2M:
                    {
                        ABBM2MProtocol protocol = new ABBM2MProtocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.PM200:
                    {
                        PM200Protocol protocol = new PM200Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.TWCPM4:
                    {
                        TWCPM4Protocol protocol = new TWCPM4Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;
                    }
                }
                ReadThread = new Thread(Analysis);
                ReadThread.Start();
            }
            else
            {
                if (ReadThread != null)
                {
                    ReadThread.Abort();
                }
            }
        }