Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
AnswerRe: exe Pin
Vasudevan Deepak Kumar3-Oct-05 19:20
Vasudevan Deepak Kumar3-Oct-05 19:20 
QuestionExchange Server Contacts Export Pin
oskardiazdeleon3-Oct-05 17:28
oskardiazdeleon3-Oct-05 17:28 
QuestionRemoving all non-alphanumeric values Pin
econner3-Oct-05 17:21
econner3-Oct-05 17:21 
AnswerRe: Removing all non-alphanumeric values Pin
S. Senthil Kumar3-Oct-05 18:30
S. Senthil Kumar3-Oct-05 18:30 
GeneralRe: Removing all non-alphanumeric values Pin
econner3-Oct-05 18:50
econner3-Oct-05 18:50 
GeneralRe: Removing all non-alphanumeric values Pin
S. Senthil Kumar3-Oct-05 19:16
S. Senthil Kumar3-Oct-05 19:16 
GeneralRe: Removing all non-alphanumeric values Pin
econner4-Oct-05 6:01
econner4-Oct-05 6:01 
QuestionSimultaneously Write to and Read from the same file Pin
CNU3-Oct-05 16:26
CNU3-Oct-05 16:26 
Hi,
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing:

<br />
public CLogHandler()<br />
{<br />
this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read);<br />
				this.m_swLog = new StreamWriter(this.m_fsLog);<br />
				if(this.m_swLog != null)	this.m_swLog.AutoFlush = true;	<br />
}<br />
<br />
pubic WriteLogMessage()<br />
{<br />
if(this.m_swLog != null)	this.m_swLog.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + aMsg + Environment.NewLine);<br />
}<br />


One of the requirements is to display the current log file contents in a child form. So, I open the log file for reading like this :

<br />
System.IO.FileStream fs = new FileStream(this.m_strCurrentFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);<br />
				System.IO.StreamReader sr = new StreamReader(fs);<br />
				<br />
				while(sr.Peek() > -1)	this.DisplayLogText(sr.ReadLine() + Environment.NewLine);<br />
				<br />
				fs.Close();	<br />


As you see, when I open the file for writing, I'm granting FileShare.Read, which means other processes can open the file for reading. But when I try to open the file for reading, it gives IOException that the file is being used by another process.

So, how can we write and read to and from a file simultaneously in the same program (ofcourse, without stopping the write process)??


Cheers
CNU
QuestionCopying a Reference Type? Pin
YawgmothIII3-Oct-05 14:13
YawgmothIII3-Oct-05 14:13 
AnswerRe: Copying a Reference Type? Pin
Jose Lamas Rios3-Oct-05 16:16
Jose Lamas Rios3-Oct-05 16:16 
AnswerRe: Copying a Reference Type? Pin
S. Senthil Kumar3-Oct-05 18:36
S. Senthil Kumar3-Oct-05 18:36 
GeneralRe: Copying a Reference Type? Pin
Robert Rohde3-Oct-05 21:00
Robert Rohde3-Oct-05 21:00 
AnswerRe: Copying a Reference Type? Pin
Venkat60704-Oct-05 1:09
Venkat60704-Oct-05 1:09 
Questionsome questions... Pin
Sasuko3-Oct-05 12:11
Sasuko3-Oct-05 12:11 
AnswerRe: some questions... Pin
seee sharp3-Oct-05 17:50
seee sharp3-Oct-05 17:50 
AnswerRe: some questions... Pin
S. Senthil Kumar3-Oct-05 18:38
S. Senthil Kumar3-Oct-05 18:38 
Questionxml parsing of IIS log files Pin
Member 23270093-Oct-05 11:17
Member 23270093-Oct-05 11:17 
AnswerRe: xml parsing of IIS log files Pin
leppie3-Oct-05 20:31
leppie3-Oct-05 20:31 
GeneralRe: xml parsing of IIS log files Pin
Member 23270094-Oct-05 11:02
Member 23270094-Oct-05 11:02 
QuestionGraph vertex edge weights Pin
Gedrain3-Oct-05 10:52
Gedrain3-Oct-05 10:52 
AnswerRe: Graph vertex edge weights Pin
Mohamad Al Husseiny3-Oct-05 12:47
Mohamad Al Husseiny3-Oct-05 12:47 
GeneralRe: Graph vertex edge weights Pin
Gedrain4-Oct-05 8:26
Gedrain4-Oct-05 8:26 
QuestionWebresponse Question Pin
Steve Messer3-Oct-05 10:13
Steve Messer3-Oct-05 10:13 
GeneralRe: Webresponse Question Pin
Guffa3-Oct-05 14:19
Guffa3-Oct-05 14:19 
GeneralRe: Webresponse Question Pin
Steve Messer3-Oct-05 14:45
Steve Messer3-Oct-05 14:45 

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.