I've an application which reads and writes to a shared excel using C#.
The application runs on different computers and whenever anybody writes to the excel a pop-up appears on all the computers in which the application is running and displays the recent message written to excel file.
I am using FileSystemWatcher and an event is raised whenever something is written to the file.
If this event occurs I am reading the excel file from each of the process and displaying the latest message.
Now, when I am reading the excel file from different computers(processes) at the same time. All the processes does not get the latest message.
I am opening the excel in readOnly and releasing the excel object successfully.
Also, I have found that when many processes are trying to read from the same excel at the same time. The excel tends to crash.
I have added a thread.sleep(3000) so that there is a delay in reading the excel file. This did help but still the excel throws error messages.
Is there anyway that I can read excel file one after the other from each process?
what is the error message? or COM exception code?
Is there any inner exception?
These are valuable tips on what the problem could be!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
My programs never have bugs, they just develop random features.
It sounds like you are taking every step possible to overcome some very common problems with network shares.
The FileSystemWatcher and sleep(3000) may not be enough. Try creating a locked file (FileStream with Non-Sharing Mode) that your "listeners" try to access. Remove the lock once the message has been added and the excel file is written.
But my guess is that you will never get rid of this problem. File access using network shares are never reliable when accessed from multiple computers simultaneously (in my experience).
Last Visit: 31-Dec-99 19:00 Last Update: 29-Nov-15 1:01