Click here to Skip to main content
15,896,342 members
Home / Discussions / C#
   

C#

 
Questionarray property Pin
TMattC1-Jan-15 5:13
TMattC1-Jan-15 5:13 
AnswerRe: array property Pin
Thomas Daniels1-Jan-15 5:29
mentorThomas Daniels1-Jan-15 5:29 
GeneralRe: array property Pin
PIEBALDconsult1-Jan-15 5:47
mvePIEBALDconsult1-Jan-15 5:47 
AnswerRe: array property Pin
OriginalGriff1-Jan-15 6:07
mveOriginalGriff1-Jan-15 6:07 
GeneralRe: array property Pin
harold aptroot1-Jan-15 6:16
harold aptroot1-Jan-15 6:16 
AnswerRe: array property Pin
BillWoodruff1-Jan-15 9:23
professionalBillWoodruff1-Jan-15 9:23 
AnswerRe: array property Pin
BillWoodruff2-Jan-15 2:48
professionalBillWoodruff2-Jan-15 2:48 
Question(solved) Multiple reads of a file when it is open in another application ? Pin
BillWoodruff1-Jan-15 4:15
professionalBillWoodruff1-Jan-15 4:15 
I am working with a FileSystemWatcher and intercepting 'FileCreated and 'FileChanged events: no problem there.

The file is kept open in a simple text editor application.

I read the file using this code:

C#
private string[] theFileContents;

// edit: changed after OriginalGriff and Pete O'Hanlon pointed out code here
// was opening the file twice
private void ReadTheFile(string thePath)
{
    theFileContents = File.ReadAllLines(thePath);                       
}
If I start with the file inside the watched folder, the first time I change the text in the text editor and save, I get the notification, and can verify I am reading the changed text.

The second time I edit and save in the text editor I get the "in use" error System.IO.IOException:

"The process cannot access the file because it is being used by another process.

If I start with the file outside the watched folder and then drag-drop it in: I get the 'created notification, and can read the file.

If I then edit the file in the text editor and save, I get the "in use" error again.

Is there a way to keep the file open for reading during multiple FileSystemWatcher events ?

If there isn't, I am thinking that maybe copying the file, and then reading the copy, and then discarding the copy is one possible strategy.

Appreciate your thoughts !
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push»  Wittgenstein


modified 2-Jan-15 8:25am.

AnswerRe: Multiple reads of a file when it is open in another application ? Pin
OriginalGriff1-Jan-15 4:42
mveOriginalGriff1-Jan-15 4:42 
GeneralRe: Multiple reads of a file when it is open in another application ? Pin
BillWoodruff1-Jan-15 6:03
professionalBillWoodruff1-Jan-15 6:03 
GeneralRe: Multiple reads of a file when it is open in another application ? Pin
OriginalGriff1-Jan-15 6:12
mveOriginalGriff1-Jan-15 6:12 
GeneralRe: Multiple reads of a file when it is open in another application ? Pin
BillWoodruff1-Jan-15 21:55
professionalBillWoodruff1-Jan-15 21:55 
GeneralRe: Multiple reads of a file when it is open in another application ? Pin
OriginalGriff1-Jan-15 23:05
mveOriginalGriff1-Jan-15 23:05 
AnswerRe: Multiple reads of a file when it is open in another application ? Pin
Pete O'Hanlon1-Jan-15 23:04
mvePete O'Hanlon1-Jan-15 23:04 
GeneralRe: Multiple reads of a file when it is open in another application ? Pin
BillWoodruff2-Jan-15 2:22
professionalBillWoodruff2-Jan-15 2:22 
QuestionReference to array element Pin
Krishnakumartg31-Dec-14 22:55
Krishnakumartg31-Dec-14 22:55 
AnswerRe: Reference to array element Pin
OriginalGriff31-Dec-14 23:56
mveOriginalGriff31-Dec-14 23:56 
GeneralRe: Reference to array element Pin
BillWoodruff1-Jan-15 4:24
professionalBillWoodruff1-Jan-15 4:24 
GeneralRe: Reference to array element Pin
OriginalGriff1-Jan-15 4:34
mveOriginalGriff1-Jan-15 4:34 
GeneralRe: Reference to array element Pin
harold aptroot1-Jan-15 4:44
harold aptroot1-Jan-15 4:44 
GeneralRe: Reference to array element Pin
Krishnakumartg26-Jan-15 18:52
Krishnakumartg26-Jan-15 18:52 
Question[Solved]C# Database Image Manager Pin
rattlerrFx31-Dec-14 10:44
rattlerrFx31-Dec-14 10:44 
AnswerRe: C# Database Image Manager Pin
Richard Andrew x6431-Dec-14 11:13
professionalRichard Andrew x6431-Dec-14 11:13 
GeneralRe: C# Database Image Manager Pin
rattlerrFx31-Dec-14 11:25
rattlerrFx31-Dec-14 11:25 
AnswerRe: C# Database Image Manager Pin
Richard Andrew x6431-Dec-14 11:27
professionalRichard Andrew x6431-Dec-14 11:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.