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

C#

 
GeneralRe: Working On Communication Protocols Pin
Addy Tas12-Dec-11 10:46
Addy Tas12-Dec-11 10:46 
GeneralRe: Working On Communication Protocols Pin
BobJanova13-Dec-11 23:22
BobJanova13-Dec-11 23:22 
AnswerRe: Working On Communication Protocols Pin
Eddy Vluggen11-Dec-11 12:32
professionalEddy Vluggen11-Dec-11 12:32 
JokeRe: Working On Communication Protocols Pin
Peter_in_278011-Dec-11 13:33
professionalPeter_in_278011-Dec-11 13:33 
GeneralRe: Working On Communication Protocols Pin
Eddy Vluggen12-Dec-11 6:04
professionalEddy Vluggen12-Dec-11 6:04 
Questionconflict of interest, COI...in systemwatcher and stream reader... Pin
beh760610-Dec-11 23:34
beh760610-Dec-11 23:34 
AnswerRe: conflict of interest, COI...in systemwatcher and stream reader... Pin
Eddy Vluggen11-Dec-11 12:26
professionalEddy Vluggen11-Dec-11 12:26 
AnswerRe: conflict of interest, COI...in systemwatcher and stream reader... Pin
Luc Pattyn11-Dec-11 13:10
sitebuilderLuc Pattyn11-Dec-11 13:10 
A couple of things to watch for:

1.
FileSystemWatcher looks for file system activity, and fires events when some file operations happen (or start to happen). The number of events is undefined; creating and filling a big file may generate several Changed events.

2.
FileSystemWatcher does NOT signal the end of a file operation, so you won't know when the writing process is done writing.

3.
One way to cope with the above is by inserting a delay: after a Created or a Changed event, just wait one minute, and only then do what you intended.

4.
Another work-around is using two files (this assumes you control the producer: have it create the actual file of interest, and when done, create a small "semaphore" file, optimally using simple code such as
File.WriteAllText("someFolder\semaphore.dat", "there is a new file called someFolder\myActualDataFile.txt");

Then have your FileSystemWatcher watch for the semaphore file only.

5.
When reading files or file streams, you must mjake sure to close them properly. Calling Close() or Dispose() normally takes care of that. Applying a using construct is a very good way to make sure it always happens:

using (StreamWriter swFromFile = new StreamWriter(logFileName)) {
    swFromFile.Write(textToAdd);
    ...
    swFromFile.Write(textToAdd);
} // file is closed properly by "using" which calls Dispose behind the scenes


Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralRe: conflict of interest, COI...in systemwatcher and stream reader... Pin
beh760611-Dec-11 15:48
beh760611-Dec-11 15:48 
Questionregular expressions groups Pin
benams10-Dec-11 22:20
benams10-Dec-11 22:20 
AnswerRe: regular expressions groups Pin
OriginalGriff11-Dec-11 0:50
mveOriginalGriff11-Dec-11 0:50 
AnswerRe: regular expressions groups Pin
PIEBALDconsult11-Dec-11 8:18
mvePIEBALDconsult11-Dec-11 8:18 
QuestionHow to set up Winforms app to avoid piracy? Pin
swampwiz10-Dec-11 5:34
swampwiz10-Dec-11 5:34 
GeneralRe: How to set up Winforms app to avoid piracy? PinPopular
harold aptroot10-Dec-11 6:00
harold aptroot10-Dec-11 6:00 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
OriginalGriff10-Dec-11 21:46
mveOriginalGriff10-Dec-11 21:46 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
Not Active10-Dec-11 6:07
mentorNot Active10-Dec-11 6:07 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
PIEBALDconsult10-Dec-11 8:21
mvePIEBALDconsult10-Dec-11 8:21 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen10-Dec-11 13:16
professionalEddy Vluggen10-Dec-11 13:16 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Addy Tas11-Dec-11 1:49
Addy Tas11-Dec-11 1:49 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen11-Dec-11 12:27
professionalEddy Vluggen11-Dec-11 12:27 
QuestionCall to REST WCF service creating a file instead of string Pin
nitin_ion10-Dec-11 1:09
nitin_ion10-Dec-11 1:09 
AnswerRe: Call to REST WCF service creating a file instead of string Pin
Richard MacCutchan10-Dec-11 2:54
mveRichard MacCutchan10-Dec-11 2:54 
Question8 queens in c# Pin
Member 84662349-Dec-11 21:34
Member 84662349-Dec-11 21:34 
AnswerRe: 8 queens in c# PinPopular
Luc Pattyn10-Dec-11 0:15
sitebuilderLuc Pattyn10-Dec-11 0:15 
GeneralRe: 8 queens in c# Pin
Member 846623410-Dec-11 14:04
Member 846623410-Dec-11 14:04 

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.