using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Channels; using System.Threading.Tasks; namespace HybirdFrameworkServices.Charger.BatCharging.Manager { /// /// 管理充电机信息 /// public class ChargerEqmManager { public Channel messageQueue; /// /// 充电机通讯连接线程 /// public void ChargerNetConnectThread() { Thread chrgConnectThread = new Thread(ChargerNetConnectFunc); chrgConnectThread.IsBackground = true; chrgConnectThread.Start(); } /// /// 充电机通讯连接 /// private void ChargerNetConnectFunc() { UnboundedChannelOptions options = new UnboundedChannelOptions(); options.SingleReader = true; messageQueue = Channel.CreateUnbounded(options); ChargerConnect(); } public void ChargerConnect() { Task.Run(() => ConsumeMessagesThread()); while (true) { //if(messageQueue.) } } public async Task ConsumeMessagesThread() { while (await messageQueue.Reader.WaitToReadAsync()) { while (messageQueue.Reader.TryRead(out var message)) { //Client_DataReceived(message); } } } } }