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

C#

 
QuestionHow do I call a C# DLL Using Visual Studio 2005 ( C# Code) Pin
Peter Usinga27-Dec-06 1:15
Peter Usinga27-Dec-06 1:15 
AnswerRe: How do I call a C# DLL Using Visual Studio 2005 ( C# Code) Pin
Andrei Ungureanu27-Dec-06 2:26
Andrei Ungureanu27-Dec-06 2:26 
AnswerRe: How do I call a C# DLL Using Visual Studio 2005 ( C# Code) Pin
ednrgc28-Dec-06 6:32
ednrgc28-Dec-06 6:32 
QuestionHow to change column order in DataGrid Pin
AndrusM27-Dec-06 0:45
AndrusM27-Dec-06 0:45 
QuestionHow to move to first column in DataGrid Pin
AndrusM27-Dec-06 0:44
AndrusM27-Dec-06 0:44 
Question.net 2.0 visual style Pin
fmardani27-Dec-06 0:35
fmardani27-Dec-06 0:35 
AnswerRe: .net 2.0 visual style [modified] Pin
Luc Pattyn27-Dec-06 6:57
sitebuilderLuc Pattyn27-Dec-06 6:57 
GeneralRe: .net 2.0 visual style Pin
Dan Neely27-Dec-06 7:24
Dan Neely27-Dec-06 7:24 
GeneralRe: .net 2.0 visual style Pin
Luc Pattyn27-Dec-06 8:14
sitebuilderLuc Pattyn27-Dec-06 8:14 
AnswerRe: .net 2.0 visual style Pin
Thomas Stockwell28-Dec-06 7:28
professionalThomas Stockwell28-Dec-06 7:28 
Question.NET + bluetooth connection Pin
Ashutosh.options4u27-Dec-06 0:28
Ashutosh.options4u27-Dec-06 0:28 
AnswerRe: .NET + bluetooth connection Pin
Niiiissssshhhhhuuuuu27-Dec-06 2:40
Niiiissssshhhhhuuuuu27-Dec-06 2:40 
Questionhow to show ContextMenu on html code or tag ? Pin
hdv21227-Dec-06 0:28
hdv21227-Dec-06 0:28 
Questionmulitine in datagrid Pin
karthikmnm26-Dec-06 23:55
karthikmnm26-Dec-06 23:55 
Questionhow to capture logfile changes into a text box Pin
Rafferty Uy26-Dec-06 22:58
Rafferty Uy26-Dec-06 22:58 
AnswerRe: how to capture logfile changes into a text box Pin
Marek Grzenkowicz27-Dec-06 0:47
Marek Grzenkowicz27-Dec-06 0:47 
AnswerRe: how to capture logfile changes into a text box Pin
PIEBALDconsult27-Dec-06 3:29
mvePIEBALDconsult27-Dec-06 3:29 
GeneralRe: how to capture logfile changes into a text box Pin
Luc Pattyn27-Dec-06 7:16
sitebuilderLuc Pattyn27-Dec-06 7:16 
GeneralRe: how to capture logfile changes into a text box Pin
Rafferty Uy27-Dec-06 15:47
Rafferty Uy27-Dec-06 15:47 
GeneralRe: how to capture logfile changes into a text box Pin
Luc Pattyn27-Dec-06 16:48
sitebuilderLuc Pattyn27-Dec-06 16:48 
GeneralRe: how to capture logfile changes into a text box Pin
Rafferty Uy27-Dec-06 18:50
Rafferty Uy27-Dec-06 18:50 
GeneralRe: how to capture logfile changes into a text box Pin
Luc Pattyn28-Dec-06 5:00
sitebuilderLuc Pattyn28-Dec-06 5:00 
Hi Rafferty,

I don't have a general solution available, so I did some experiments.

I have one process that periodically (100msec) writes a string to a file;
my writer code reopens the file for every write access
(with a single open, a reader would be unable to access the file at all):
private void output(string s) {
	try {
		StreamWriter sw=new StreamWriter(fileSpec, true); // append !
		sw.WriteLine(s);
		sw.Close();
	} catch (Exception exc) {
		timelog(exc.Message);
	}
}


I have another process that periodically (but at a lower frequency, 1sec) tries
to read one or more lines; the code is similar to yours.
(assume seek is zero and delay is false):
private void input() {
	try {
		StreamReader sr=new StreamReader(fileSpec);
		sr.BaseStream.Position=seek;
		if (delay) Thread.Sleep(1000);	// try to block producer !
		while((string s=sr.ReadLine())!=null) {
			log("line "+line+": "+s); // process the input data
			seek=sr.BaseStream.Position;
		}
		sr.Close();
	} catch (Exception exc) {
		timelog(exc.Message);
	}
}

This duo typically behaves well, I guess because the reader is simple enough
so it can do its job without a task reschedule, so the writer never is active
while the reader has file access.

But when I set delay true (reader keeping file accessed while relinquishing CPU), the writer starts to fail with "cannot access file", exactly as I was expecting.

I am still looking for a general solution; so far I would say the reader should
collect new data and avoid operations that take time or may relinquish the CPU.
But if the OS, for whatever reason, interrupts the input method and reactivates
the writer, things will go wrong there.

Smile | :)



Luc Pattyn

GeneralRe: how to capture logfile changes into a text box Pin
Rafferty Uy28-Dec-06 13:47
Rafferty Uy28-Dec-06 13:47 
QuestionUsing a navigator panel Pin
quiteSmart26-Dec-06 22:56
quiteSmart26-Dec-06 22:56 
QuestionMDIchild form goes behind the panel Pin
thunaivanu26-Dec-06 22:16
thunaivanu26-Dec-06 22:16 

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.