Click here to Skip to main content
15,357,219 members
Home / Discussions / C#
   

C#

 
AnswerRe: Textbox validation c# help Pin
Smart Arab2-Oct-12 11:17
MemberSmart Arab2-Oct-12 11:17 
GeneralRe: Textbox validation c# help Pin
User 94041062-Oct-12 11:27
MemberUser 94041062-Oct-12 11:27 
GeneralRe: Textbox validation c# help Pin
User 94041068-Oct-12 3:37
MemberUser 94041068-Oct-12 3:37 
QuestionMonitoring file changes and changing data within the file... Pin
JD862-Oct-12 8:31
MemberJD862-Oct-12 8:31 
AnswerRe: Monitoring file changes and changing data within the file... Pin
Smart Arab2-Oct-12 11:22
MemberSmart Arab2-Oct-12 11:22 
GeneralRe: Monitoring file changes and changing data within the file... Pin
Pete O'Hanlon3-Oct-12 2:03
mvaPete O'Hanlon3-Oct-12 2:03 
AnswerRe: Monitoring file changes and changing data within the file... Pin
Eddy Vluggen3-Oct-12 1:39
professionalEddy Vluggen3-Oct-12 1:39 
AnswerRe: Monitoring file changes and changing data within the file... Pin
Pete O'Hanlon3-Oct-12 2:26
mvaPete O'Hanlon3-Oct-12 2:26 
I would be tempted to rewrite this method like this:
C#
private static readonly object SyncLock = new object();
private void WriteFile(string file, StringBuilder sb, string oldValue)
{
  try
  {
    using (StreamWriter sw = new StreamWriter(file, false))
    {
      sw.Write(sb.ToString());
    }
    // Log
    EventLog.WriteEntry("QBiniMonitor", "Successfully removed LASTUSERNAME. Old Value: " + oldValue, EventLogEntryType.Information);
  }
  catch (IOException)
  {
    lock (SyncLock)
    {
      // Wait for 200 milliseconds
      Monitor.Wait(SyncLock, 200);
    }
    // Keep trying till the file is unlocked
    WriteFile(file, sb, oldValue);
  }
}
The using statement removes the need to explicitly close the stream, and the lock/Monitor elements help to pause the next call to WriteFile for 200 milliseconds. Without this, you have a tight loop in there with execution of WriteFile happening immediately on failure.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos


CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Monitoring file changes and changing data within the file... Pin
Dave Kreskowiak3-Oct-12 5:33
mveDave Kreskowiak3-Oct-12 5:33 
GeneralRe: Monitoring file changes and changing data within the file... Pin
Pete O'Hanlon3-Oct-12 5:37
mvaPete O'Hanlon3-Oct-12 5:37 
GeneralRe: Monitoring file changes and changing data within the file... Pin
Dave Kreskowiak3-Oct-12 13:38
mveDave Kreskowiak3-Oct-12 13:38 
AnswerRe: Monitoring file changes and changing data within the file... Pin
BobJanova3-Oct-12 2:42
MemberBobJanova3-Oct-12 2:42 
GeneralRe: Monitoring file changes and changing data within the file... Pin
Pete O'Hanlon3-Oct-12 3:10
mvaPete O'Hanlon3-Oct-12 3:10 
GeneralRe: Monitoring file changes and changing data within the file... Pin
JD863-Oct-12 13:59
MemberJD863-Oct-12 13:59 
GeneralRe: Monitoring file changes and changing data within the file... Pin
JD8612-Oct-12 5:27
MemberJD8612-Oct-12 5:27 
QuestionC# setup and deploy project templates located at? Pin
dcof2-Oct-12 5:10
Memberdcof2-Oct-12 5:10 
AnswerRe: C# setup and deploy project templates located at? Pin
isenthil2-Oct-12 6:30
Memberisenthil2-Oct-12 6:30 
GeneralRe: C# setup and deploy project templates located at? Pin
dcof2-Oct-12 17:48
Memberdcof2-Oct-12 17:48 
GeneralRe: C# setup and deploy project templates located at? Pin
Dave Kreskowiak3-Oct-12 2:28
mveDave Kreskowiak3-Oct-12 2:28 
AnswerRe: C# setup and deploy project templates located at? Pin
Dave Kreskowiak2-Oct-12 12:33
mveDave Kreskowiak2-Oct-12 12:33 
Questionsyntax Pin
messages2-Oct-12 4:29
Membermessages2-Oct-12 4:29 
AnswerRe: syntax Pin
Eddy Vluggen2-Oct-12 4:31
professionalEddy Vluggen2-Oct-12 4:31 
GeneralRe: syntax Pin
messages2-Oct-12 5:28
Membermessages2-Oct-12 5:28 
AnswerRe: syntax Pin
Richard MacCutchan2-Oct-12 5:54
mveRichard MacCutchan2-Oct-12 5:54 
GeneralRe: syntax Pin
messages2-Oct-12 6:09
Membermessages2-Oct-12 6:09 

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.