Click here to Skip to main content
15,905,875 members
Home / Discussions / C#
   

C#

 
AnswerRe: Can I write my own XBox 360 program? Pin
BillWoodruff2-Jan-15 6:56
professionalBillWoodruff2-Jan-15 6:56 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 9:20
professionaltrantrum2-Jan-15 9:20 
QuestionUnhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 4:28
turbosupramk32-Jan-15 4:28 
AnswerRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 4:35
mveDave Kreskowiak2-Jan-15 4:35 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 5:07
turbosupramk32-Jan-15 5:07 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 8:39
mveDave Kreskowiak2-Jan-15 8:39 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 6:29
turbosupramk32-Jan-15 6:29 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 8:38
mveDave Kreskowiak2-Jan-15 8:38 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 8:46
turbosupramk32-Jan-15 8:46 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 8:49
mveDave Kreskowiak2-Jan-15 8:49 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 11:10
turbosupramk32-Jan-15 11:10 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk33-Jan-15 19:13
turbosupramk33-Jan-15 19:13 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak4-Jan-15 4:30
mveDave Kreskowiak4-Jan-15 4:30 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk34-Jan-15 6:34
turbosupramk34-Jan-15 6:34 
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 

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.