Mario
Mario

Reputation: 1488

Remove duplicate lines in a file that is being used by another thread

I have a file called example.txt and I want to remove the duplicate lines in this file using my C# application.

My application is multi-threaded, and more than one thread are already accessing the file example.txt

I've tried a lot of methods but all of them returns the error:

The file {0} is already being used by another process.

Upvotes: 0

Views: 119

Answers (1)

sziszu
sziszu

Reputation: 320

You should be able to do this by specifying file share in your file stream

FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read); 

https://msdn.microsoft.com/en-us/library/system.io.fileshare(v=vs.110).aspx

Upvotes: 1

Related Questions