multithreading - what is the best multi-threading technique in c# -
I am developing an application that is running a lot of TcpListener functions, with C #.
- Listening to getting an xml message
- Read an ID from Li> A special camera based on ID takes snapshot and stores it in the folder
This is to run within 1 second, so I can take a snapshot with the camera. Using the following code, I have been delayed in executing this task:
private threads listen_thread; Public zero start_listen () {this.listen_thread = new thread (new threadstart (save_data)); This.listen_thread.Priority = ThreadPriority.Normal; This.listen_thread.Start (); } Private Zero save_data () {// work done}Is this the best multi-threading technique to use? This app is running on the Dell Powerz 2900 with 2 quad-core professors, and I think it can be fast, how can I be able to improve the latency of this code?
Code for TCListener
Int32 port = controller_port; Try {// this server IP IP address LocalADR = IPADressesPers (IIP); Server = new TCPListener (localader, port); Server.Start (); Byte [] bytes = new byte [256]; String data = null; While (true) {Console.Write ("Waiting for connection ..."); TcpClient Client = server.AcceptTcpClient (); Console.Write ("Connected!"); Data = null; NetworkStream stream = client.GetStream (); Int i; String add_data = ""; Console.Write ("Waiting ...!"); While ((i = stream read. (Byte, 0, bytes lang)) = 0) {try {string full_row = ""; Data = System.Text.Encoding.ASCII.GetString (bytes, 0, I); Console Type ("Received from Admin:" + Data); Add_data + = data; } Hold {}}}}Then I divide it to get the ID.
Comments
Post a Comment