i am creating windows application in C# in which i want to write in a multiple file with multiple threads.I am getting data from different ports and there is one file associated with every port.Is it possible that creation of thread for every port and use the same thread again and again for writing data to respective file? Suppose i am getting data from ports 10000,10001,10002 and there are three files as 10000.txt,10001.txt and 10002.txt. I have to create three threads for writing data to these three files respectively and i want to use these threads again and again.Is it possible?Please can you give a small sample of code if possible?
Share
If you let each thread handle its own file it’ll do?
So when a port reader thread is created, you open the file that belongs to that port, and store the handle to that file. Whenever you receive data, you write it to the file:
And then start them like such:
Ideally you want to separate the file writing from the port reading, but I’ll leave that up to you for the sake of simplicity.