SSIS 2008 C# Script task not producing expected outcome

Hi,
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
        };
        #endregion


       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..
blossomparkAsked:
Who is Participating?
 
lcohanDatabase AnalystCommented:
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"
0
 
blossomparkAuthor Commented:
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.