Click here to Skip to main content
15,890,186 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# vNext language design - private protected - FamilyAndAssembly Pin
Paulo Morgado1-May-14 6:21
professionalPaulo Morgado1-May-14 6:21 
QuestionString, Why does this work?? Pin
GrooverFromHolland30-Apr-14 8:53
GrooverFromHolland30-Apr-14 8:53 
AnswerRe: String, Why does this work?? Pin
BillWoodruff30-Apr-14 9:58
professionalBillWoodruff30-Apr-14 9:58 
GeneralRe: String, Why does this work?? Pin
GrooverFromHolland30-Apr-14 10:16
GrooverFromHolland30-Apr-14 10:16 
GeneralRe: String, Why does this work?? Pin
Rob Philpott1-May-14 1:51
Rob Philpott1-May-14 1:51 
AnswerRe: String, Why does this work?? Pin
Alan N1-May-14 0:58
Alan N1-May-14 0:58 
Questionwriting to a file while Looping Pin
Kasun Liyanage30-Apr-14 7:35
Kasun Liyanage30-Apr-14 7:35 
AnswerRe: writing to a file while Looping Pin
OriginalGriff30-Apr-14 8:07
mveOriginalGriff30-Apr-14 8:07 
OK...you can't see the problem yourself?

You have two different methods of adding data ready and in use in that code:
C#
StreamWriter sw = new StreamWriter("data.txt", true);
Sets up sw to append to the file data.txt - which means opening the file and acquiring an exclusive lock so the file content can;t be changed while you are writing to it.
Then:
C#
File.AppendAllText("data.txt", fileName);
Which tries to open the file data.txt for append by acquiring an exclusive lock so the file content can;t be changed while you are writing to it.

And fails, because there already is an exclusive lock open on the file...by your code. Laugh | :laugh:

So, either use the sw stream to write to the file, or get rid of it completely, and just use the File.AppendAllText method instead - but don't try to use both.

And if you do go with your own stream (which in this case is probably a good idea as you only open and lock the file once) remember to Close and Dispose the stream when you have finished - or the next time you call that code the file will still be locked from the first time!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

GeneralRe: writing to a file while Looping Pin
Kasun Liyanage30-Apr-14 8:31
Kasun Liyanage30-Apr-14 8:31 
GeneralRe: writing to a file while Looping Pin
OriginalGriff30-Apr-14 8:39
mveOriginalGriff30-Apr-14 8:39 
QuestionPower point file formatter Pin
Taimoor Hassun29-Apr-14 18:21
Taimoor Hassun29-Apr-14 18:21 
AnswerRe: Power point file formatter Pin
Richard MacCutchan29-Apr-14 20:26
mveRichard MacCutchan29-Apr-14 20:26 
GeneralRe: Power point file formatter Pin
Taimoor Hassun29-Apr-14 21:00
Taimoor Hassun29-Apr-14 21:00 
GeneralRe: Power point file formatter Pin
Richard MacCutchan29-Apr-14 21:08
mveRichard MacCutchan29-Apr-14 21:08 
GeneralRe: Power point file formatter Pin
Taimoor Hassun30-Apr-14 4:54
Taimoor Hassun30-Apr-14 4:54 
GeneralRe: Power point file formatter Pin
Chris Quinn30-Apr-14 4:57
Chris Quinn30-Apr-14 4:57 
GeneralRe: Power point file formatter Pin
Taimoor Hassun30-Apr-14 6:17
Taimoor Hassun30-Apr-14 6:17 
Questionhelp me Pin
Member 1078417429-Apr-14 14:18
Member 1078417429-Apr-14 14:18 
AnswerRe: help me Pin
Peter Leow29-Apr-14 14:36
professionalPeter Leow29-Apr-14 14:36 
AnswerRe: help me Pin
OriginalGriff29-Apr-14 20:10
mveOriginalGriff29-Apr-14 20:10 
AnswerRe: help me Pin
Rob Philpott30-Apr-14 2:17
Rob Philpott30-Apr-14 2:17 
GeneralRe: help me Pin
Pete O'Hanlon30-Apr-14 6:35
mvePete O'Hanlon30-Apr-14 6:35 
GeneralRe: help me Pin
Wes Aday30-Apr-14 14:27
professionalWes Aday30-Apr-14 14:27 
GeneralRe: help me Pin
Rob Philpott1-May-14 1:45
Rob Philpott1-May-14 1:45 
Questionhelp Pin
Member 1078417429-Apr-14 12:41
Member 1078417429-Apr-14 12:41 

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.