Last post Sep 28, 2013 12:48 PM by sureshtalla
Sep 28, 2013 01:15 AM|sureshtalla|LINK
From command line i am passing 2 arguments to the Exe File 1, 10.
So here at a time multiple users are passing the command line arguments to exe file.
Here based on the command line agrument , we are getting some data from database and storing into the DataTable.
In bin folder we have one test.txt file Here wea are opening a file and comparing the file data with the DataTable.
Once open the file, same at a time another user can't open the file.
I am getting exception process cannot access the file because it is used by another process.
But Multiple users need to access the Same file at a Time(Usres are at a time sending inputs from command prompt).
How can we do it
Sep 28, 2013 04:20 AM|HeartattacK|LINK
Do you have access to the source code? If so consider making these changes:
* Don't hit the file on each request. Load it in memory, and use it from memory.
* Use some sort of locking mechanism to ensure only one user accesses the file at a time.
* If you're only reading from the file and not writing to it, then just open the file in shared mode:
using (Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
* Worst option: put a try-catch around the reading part and loop until successful. If the file is kept open for longer periods and there are a lot of users, this would be a terrible approach.
Sep 28, 2013 12:48 PM|sureshtalla|LINK
Thanks for your reply
I used the below FileShare.Read, It's working.We can open file but we can't to write operations.
Only file can be read multiple users at a time.
using (Stream stream = new FileStream(File, FileMode.Open, FileAccess.Read, FileShare.Read))
dataReader = new StreamReader(stream);