Click here to Skip to main content
16,008,183 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: date time Pin
Luc Pattyn5-Jul-07 6:29
sitebuilderLuc Pattyn5-Jul-07 6:29 
QuestionVisual Studio 2005 Pin
Khan.Bangash5-Jul-07 2:23
Khan.Bangash5-Jul-07 2:23 
AnswerRe: Visual Studio 2005 Pin
Paul Conrad13-Jul-07 12:33
professionalPaul Conrad13-Jul-07 12:33 
Questionerror in stream reading Pin
balakpn5-Jul-07 2:03
balakpn5-Jul-07 2:03 
AnswerRe: error in stream reading Pin
Christian Graus5-Jul-07 2:09
protectorChristian Graus5-Jul-07 2:09 
GeneralRe: error in stream reading Pin
balakpn5-Jul-07 3:19
balakpn5-Jul-07 3:19 
GeneralRe: error in stream reading Pin
Christian Graus5-Jul-07 4:55
protectorChristian Graus5-Jul-07 4:55 
GeneralRe: error in stream reading Pin
Luc Pattyn5-Jul-07 6:02
sitebuilderLuc Pattyn5-Jul-07 6:02 
Hi,

I beg to differ: whoever creates/opens a file is in control regarding the
operations others can do to the same file.

one can easily share a file between threads and even processes; it suffices
to apply the correct FileShare value when creating/opening the file.

My example shows a first stream writing to a file it allows others to read,
and a second stream reading from same file allowing others everything:
string filename="streamTest.txt";
using(FileStream fw=new FileStream(filename, FileMode.Create,
		FileAccess.Write, FileShare.Read)) {
	using(StreamWriter tw=new StreamWriter(fw)) {
		tw.WriteLine("Created new file");
		using(FileStream fr=new FileStream(filename, FileMode.Open,
				FileAccess.Read, FileShare.ReadWrite)) {
			using(StreamReader tr=new StreamReader(fr)) {
				for(int i=0; i<10; i++) {
					tw.WriteLine("line "+i);
					tw.Flush();
					string s=tr.ReadLine();
					Console.WriteLine(s);
				}
			}
		}
	}
}


BTW the flush is there to undo the buffering that takes place in these streams;
without it there probably would be nothing to read when the short loop
terminates; for longer streams, flushing is not needed ! And normally
the reader should continue to read after the writer has done, my example does not.

Smile | :)

PS: sorry for posting a C# example in a VB.NET forum !



GeneralRe: error in stream reading Pin
balakpn5-Jul-07 19:53
balakpn5-Jul-07 19:53 
GeneralRe: error in stream reading Pin
Luc Pattyn5-Jul-07 23:48
sitebuilderLuc Pattyn5-Jul-07 23:48 
GeneralRe: error in stream reading Pin
balakpn6-Jul-07 3:20
balakpn6-Jul-07 3:20 
GeneralRe: error in stream reading Pin
Luc Pattyn6-Jul-07 3:26
sitebuilderLuc Pattyn6-Jul-07 3:26 
Questionword document Pin
hsuresh5-Jul-07 0:39
hsuresh5-Jul-07 0:39 
AnswerRe: word document Pin
Christian Graus5-Jul-07 1:16
protectorChristian Graus5-Jul-07 1:16 
GeneralRe: word document Pin
Christian Graus5-Jul-07 1:43
protectorChristian Graus5-Jul-07 1:43 
AnswerRe: word document Pin
Sathesh Sakthivel5-Jul-07 1:30
Sathesh Sakthivel5-Jul-07 1:30 
GeneralRe: word document Pin
Christian Graus5-Jul-07 2:22
protectorChristian Graus5-Jul-07 2:22 
AnswerRe: dim f as string Pin
CPallini5-Jul-07 0:48
mveCPallini5-Jul-07 0:48 
GeneralRe: dim f as string Pin
magedhv5-Jul-07 1:05
magedhv5-Jul-07 1:05 
GeneralRe: dim f as string Pin
Christian Graus5-Jul-07 1:13
protectorChristian Graus5-Jul-07 1:13 
QuestionNumerical textbox validation, how to handle an empty string? [modified] Pin
MatthysDT5-Jul-07 0:09
MatthysDT5-Jul-07 0:09 
AnswerRe: Numerical textbox validation, how to handle an empty string? Pin
SHatchard5-Jul-07 0:19
SHatchard5-Jul-07 0:19 
QuestionRe: Numerical textbox validation, how to handle an empty string? Pin
MatthysDT5-Jul-07 1:25
MatthysDT5-Jul-07 1:25 
NewsRe: Numerical textbox validation, how to handle an empty string? Pin
MatthysDT5-Jul-07 1:55
MatthysDT5-Jul-07 1:55 
AnswerRe: Numerical textbox validation, how to handle an empty string? Pin
cutequencher5-Jul-07 6:05
cutequencher5-Jul-07 6:05 

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.