Getting started with C # thread event

zhaozj2021-02-16  112

Recently, I have developed an instant messaging system. Since I have a busy time, add 4,5 exams, there is no time to write some feelings. Now I am preparing to slow down the time, or my Dengfeng is going to be a pavilion. :), the retiring is correct, the client needs to transfer the file to the server, and it is transmitted to another client, but the target customer is not yet, so the function of the message is also true. Transfer files are not only one, may contain n directory and n files, usually put the transferred file directory list in a loop, write to TCP streams, including file size and file name, in this case If the previous file has not been transferred, the file in the for loop cannot be written to the TCP stream, how to solve this problem? My idea is to put autoretetevent in the for loop, generate a waiter, until the last file is transferred, set the AutoreteTevent into non-activation so that the for continues to transfer the next file, here I didn't give you TCP examples And it is a model for this problem. Please see the sample code below

Using system; using system.threading;

Namespace automes {class mymainclass {const int number = 10; static automoresevent myresest = new automoretest (false);

Static int number; static void main () {thread myreaderthread = new thread (New Threadstart (MyReadstart (MyReadThreadProc); MyReaderthread.Name = "ReadertHread"; myReaderthread.start ();}

Static void myreadthreadProc () {for (int i = 0; i

Static void profile () {Console.Writeline ("static process sendfile:" Number); console.writeline ("Process End!"); MyResevent.Set ();

}

转载请注明原文地址:https://www.9cbs.com/read-13301.html

New Post(0)