SSIS 2008 C# Script task not producing expected outcome

Posted on 2014-03-06
Last Modified: 2016-02-10
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..
Question by:blossompark
LVL 39

Accepted Solution

lcohan earned 500 total points
ID: 39910578
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"

Author Comment

ID: 39911147
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?

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question