Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:23:06+00:00 2026-05-23T12:23:06+00:00

Okay, this is pretty weird. I made an app that listens for changes inside

  • 0

Okay, this is pretty weird.

I made an app that listens for changes inside a file, and then duplicate those changes to another file. Everything was working alright, I changed almost nothing, tried to rollback my changes but still no luck.

So here is the problem : I have a FileSystemWatcher, and a method that gets called on the “Changed” event. For some time now, I noticed that my app crashes when there’s a change so I looked at my method and everything is just fine. In fact, it runs when I put a breakpoint inside it. But if I remove the breakpoint then it crashes, leaving no worrying errors (I think) in the output other than:

The thread 'vshost.NotifyLoad' (0xa84) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x17e8) has exited with code 0 (0x0).
'TimeDataDuplicator.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\Tommy Bergeron\Documents\Visual Studio 2010\Projects\vs-projects\TimeDataDuplicator\TimeDataDuplicator\bin\Debug\TimeDataDuplicator.exe', Symbols loaded.
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
The program '[6240] TimeDataDuplicator.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[6240] TimeDataDuplicator.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

It is very weird that everything runs fine when there’s no breakpoint… I tried cleaning my solution and my project but nothing worked.

Any ideas? Has anyone ever stumbled upon this?

Thanks a lot!


Here’s the watcher:

private void StartWatcher()
{
    FileSystemWatcher watcher = new FileSystemWatcher();

    // Répertoire
    watcher.Path = @"C:\Symcod_data";

    // Nom du fichier à "watcher"
    watcher.Filter = "FILE_MSG.OK";

    // Choix des événements à notifier
    watcher.NotifyFilter = NotifyFilters.Size;

    // Assignation de méthode pour les événements choisies.
    watcher.Changed += FileHasChanged;

    // Début de l'observation
    watcher.EnableRaisingEvents = true;

    WriteLogMessage("TDD_WATCH_STARTED");
}

And here’s the method that gets called:

void FileHasChanged(object source, FileSystemEventArgs e)
{
    // Lecture du fichier original
    using (StreamReader fileReader = new StreamReader(originalFile))
    {
        // On garde en mémoire le contenu du fichier dupliqué
        StreamReader duplicatedCheckReader = new StreamReader(duplicatedFile);
        string duplicatedCheckContent = duplicatedCheckReader.ReadToEnd();
        duplicatedCheckReader.Close();

        // Traitement du contenu du fichier original
        string line;
        string middleLineContent;   // Contiendra seulement le millieu de la ligne (sans les caractères spéciaux)
        while ((line = fileReader.ReadLine()) != null)
        {
            // On se sert seulement que le millieu de la ligne pour faire la recherche des doublons
            middleLineContent = line.Substring(line.IndexOf("-") + 1, 16);

            // Vérification des doublons, si le doublon n'est trouvé on écrit dans le fichier
            if (!Regex.IsMatch(duplicatedCheckContent, middleLineContent))
            {
                // Initialisation de l'écriture
                try
                {
                    using (StreamWriter fileWriter = new StreamWriter(duplicatedFile, true))
                    {
                        fileWriter.WriteLine(line);
                    }

                    WriteLogMessage("WriteLine_SUCCESS (" + line + ")");
                }
                catch (Exception ex)
                {
                    WriteLogMessage("WriteLine_FAIL [Exception: " + ex.InnerException + "] (" + line + ")");
                }
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:23:06+00:00Added an answer on May 23, 2026 at 12:23 pm

    I assume that the problem is one of your two StreamReaders or the StreamWriter. I assume you try to access a file that is still locked by some other process or even by your own process.

    Try to put a try catch around the complete code of your event handler. This will show, that the exception is happening in your event handler and not someplace else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this one's pretty straightforward. I'm creating a checkbox in my Page.xaml.cs file, and
Okay this is a fairly broad question. This is my first App and I'm
Okay this is my 4th question today on Scheme, still pretty new to Scheme,
Okay so this is another question about a previous question I asked: Rookie SQL
okay this might be a pretty lame and basic question but its stuck in
Okay, This one is pretty simmilar to my last one, but I don't get
Okay so I was just starting this rails app and generated my first model
Okay, I'm trying to create a simple app that will draw a shape (I'm
Okay, so far this works in Chrome, but not Firefox. It's pretty simple so
I'm pretty new to this whole deployment thing. I've deployed my app once before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.