public void EnqueueTest() { ThreadBridge.Enqueue(() => { Console.WriteLine("EnqueueTest"); }); }
/// <summary> /// 廣播訊息 /// </summary> /// <param name="message"></param> public void Broadcasting(byte[] pkg, ushort dataType) { var newTask = new AckTask() { DataBytes = pkg, DataType = dataType, StartTime = DateTime.Now }; fCastingMessage.Enqueue(newTask); }
/// <summary> /// 接收client 連線 /// </summary> /// <param name="tokenObj"></param> private void ListenerAsync(object tokenObj) { CancellationToken token = ( CancellationToken )tokenObj; //啟動接收 10個連線數 fTcpListener.Start(10); //端點資訊 var info = ( IPEndPoint )fTcpListener.Server.LocalEndPoint; //開始工作囉! while (!fToken.IsCancellationRequested) { try { OnStatus.OnFireMessage(string.Format("[Server] 等待Client連線...Port:{0}", info.Port)); //執行續會所在這,一直到有新的連線才會繼續走 TcpClient client = fTcpListener.AcceptTcpClient( ); client.NoDelay = true; client.SendBufferSize = 1024 * 1024; client.ReceiveBufferSize = 1024 * 1024; //丟到平行資料結構 //這個queue的進出要很快,才不會影響到連線效率 var currentClient = new ProxyClient(client, OnStatus.OnFireMessage); fClientTmpQueue.Enqueue(currentClient); OnStatus.OnFireMessage(string.Format("[Clinet] 來自{0}的連線...Port:{1}", currentClient.Address, info.Port)); // log OnConnectionStatus.OnFireMessage(currentClient); } catch (SocketException se) { OnStatus.OnFireMessage(string.Format("SocketCode:{0}\r\n{1}", se.SocketErrorCode, se.ToString( ))); } catch (Exception e) { OnStatus.OnFireMessage(e.ToString( )); } } //Request 取消 token.ThrowIfCancellationRequested( ); }
public void DequeueTest1() { ThreadBridge.Enqueue(() => { Console.WriteLine("EnqueueTest1"); }); ThreadBridge.Enqueue(() => { Console.WriteLine("EnqueueTest2"); }); //Dequeue all. //ThreadBridge.Dequeue(); //Dequeue one. ThreadBridge.Dequeue(1); }
/// <summary> /// 將想要踢出的連線 加入待移除清單裡 /// </summary> /// <param name="willRemoveClients">欲剔除的連線</param> public void RemoveClients(List <ProxyClient> willRemoveClients) { fClientMoveQueue.Enqueue(willRemoveClients.ToArray()); }