SSIS 2008 C# Script task not producing expected outcome

blossompark used Ask the Experts™
I have the following script
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;

namespace ST_07bc0354bae645e8bf2e65be651aeec0.csproj
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

        #region VSTA generated code
        enum ScriptResults
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure

       public void Main()
            // Create a new FileSystemWatcher and set its properties.
            FileSystemWatcher watcher = new FileSystemWatcher();

            //Watch for changes in the following directory
            watcher.Path = @"C:\Test\";

            /* Watch for changes in  LastWrite times in the  directory. */
            watcher.NotifyFilter = NotifyFilters.LastWrite;

            // Add event handlers.
              watcher.Changed += new FileSystemEventHandler(OnChanged);
          // Begin watching.
        watcher.EnableRaisingEvents = true;
        watcher.WaitForChanged(WatcherChangeTypes.All, 20000);

            // Define the event handlers. 
    private static void OnChanged(object source, FileSystemEventArgs e)
        // Specify what is done when a file is  created, 
             MessageBox.Show("Hello, File exists");


Open in new window

which watches the specified folder for a specified time.
If a file is saved to the folder during the watch period, I expect the Message  in the event handler to display.
However, it is not displaying. The task waits for the specified time , the box remaining yellow
scripttaskwaiting.jpgafter the time has elapsed, it finishes, going to green…
FileSystemWatcherTask-suceeds.jpgbut no message box appears,
any guidance appreciated..
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Analyst
That IS because that's exactly what is it coded for it to do - check that folder for "specified time." and "after the time has elapsed, it finishes, going to green"


Hi lcohan,
thanks for your comment.
When I drop the file into the folder during the "watch" period should it not then trigger a call to the onChanged Event Handler which displays the message box?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial