Click here to Skip to main content
       

C#

 
GeneralRe: C# Windows application not responding after 30 minutes PinmentorDaveyM694-Oct-12 1:34 
GeneralRe: C# Windows application not responding after 30 minutes Pinmembersujithkumarsl4-Oct-12 11:17 
QuestionTextbox validation c# help PinmemberRobbie Kleman2-Oct-12 9:57 
AnswerRe: Textbox validation c# help PinmemberMatt T Heffron2-Oct-12 11:38 
AnswerRe: Textbox validation c# help PinmemberSmart Arab2-Oct-12 12:17 
GeneralRe: Textbox validation c# help PinmemberRobbie Kleman2-Oct-12 12:27 
GeneralRe: Textbox validation c# help PinmemberRobbie Kleman8-Oct-12 4:37 
QuestionMonitoring file changes and changing data within the file... PinmemberJD862-Oct-12 9:31 
What would be a good way to monitor a .ini file?
 
What I want to do is when the file has changed, I need to read the file and find specific text and change it and save the file.
 
I've attempted the file system watcher with little luck. The problem is it is firing before the file is unlocked. I have also tried to put a method in there to check if the file was locked which basically opens the file and on exception returns true if locked otherwise false.
 
I have also tried a looping method like this:
private void WriteFile(string file, StringBuilder sb, string oldValue)
        {
            StreamWriter sw = null;
            try
            {
                sw = new StreamWriter(file, false);
                sw.Write(sb.ToString());
                sw.Close();
 
                // Log
                EventLog.WriteEntry("QBiniMonitor", "Successfully removed LASTUSERNAME. Old Value: " + oldValue, EventLogEntryType.Information);
            }
            catch (IOException)
            {
                // Keep trying till the file is unlocked
                WriteFile(file, sb, oldValue);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                    sw.Dispose();
                }
            }
        }
 
It still errored out after it changes the value a couple times in a row. It changes it a couple times but then ends up with a uncaught IOException somehow
AnswerRe: Monitoring file changes and changing data within the file... PinmemberSmart Arab2-Oct-12 12:22 
GeneralRe: Monitoring file changes and changing data within the file... PinprotectorPete O'Hanlon3-Oct-12 3:03 
AnswerRe: Monitoring file changes and changing data within the file... PinmemberEddy Vluggen3-Oct-12 2:39 
AnswerRe: Monitoring file changes and changing data within the file... PinprotectorPete O'Hanlon3-Oct-12 3:26 
GeneralRe: Monitoring file changes and changing data within the file... PinmvpDave Kreskowiak3-Oct-12 6:33 
GeneralRe: Monitoring file changes and changing data within the file... PinprotectorPete O'Hanlon3-Oct-12 6:37 
GeneralRe: Monitoring file changes and changing data within the file... PinmvpDave Kreskowiak3-Oct-12 14:38 
AnswerRe: Monitoring file changes and changing data within the file... PinmemberBobJanova3-Oct-12 3:42 
GeneralRe: Monitoring file changes and changing data within the file... PinprotectorPete O'Hanlon3-Oct-12 4:10 
GeneralRe: Monitoring file changes and changing data within the file... PinmemberJD863-Oct-12 14:59 
GeneralRe: Monitoring file changes and changing data within the file... PinmemberJD8612-Oct-12 6:27 
QuestionC# setup and deploy project templates located at? Pinmemberdcof2-Oct-12 6:10 
AnswerRe: C# setup and deploy project templates located at? Pinmemberisenthil2-Oct-12 7:30 
GeneralRe: C# setup and deploy project templates located at? Pinmemberdcof2-Oct-12 18:48 
GeneralRe: C# setup and deploy project templates located at? PinmvpDave Kreskowiak3-Oct-12 3:28 
AnswerRe: C# setup and deploy project templates located at? PinmvpDave Kreskowiak2-Oct-12 13:33 
Questionsyntax Pinmembermessages2-Oct-12 5:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 28 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid