Hi,
I've got a c#-winforms application. One task of that application is to execute a SQL-Server DTS package. I imported DTS into .NET like Microsoft descriped it. In my first attempt I executed the DTS this way:
Code:
// ... init code
try
			  {
			  m_dlgCreate = new DlgCreate();
			  m_package = new Package2Class();
        m_package.LoadFromStorageFile(
          ".\\dts\\mydts.dts",
          null,
          null,
          null,
          "mydts",
          ref m_pVarPersistStgOfHost);
        }
      catch( System.Runtime.InteropServices.COMException /*cex*/ )
        {
        MessageBox.Show( "Unknown error while loading DTS template!", "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error );
        }

// ..execution code
private bool executeDTS()
    {
      try
        {
        // parse needed property values to the DTS package
        Task task = m_package.Tasks.Item( 1 ); // the package only contains 1 task
        task.Properties.Item( "SourceServer"        ).Value = cbxServer.SelectedItem.ToString();
        task.Properties.Item( "SourceLogin"         ).Value = txtUser.Text;
        task.Properties.Item( "SourcePassword"      ).Value = txtPwd.Text;
        //Source and Destination have to be the same server
        task.Properties.Item( "DestinationServer"   ).Value = cbxServer.SelectedItem.ToString(); 
        task.Properties.Item( "DestinationLogin"    ).Value = txtUser.Text;
        task.Properties.Item( "DestinationPassword" ).Value = txtPwd.Text;
        task.Properties.Item( "DestinationDatabase" ).Value = txtPrjDb.Text;
      
        // execute DTS
        m_package.Execute();
        
        // save last values
        m_package.SaveToStorageFile( ".\\dts\\mydts.dts", null, null, ref m_pVarPersistStgOfHost , false );
        }
      catch( System.Runtime.InteropServices.COMException /*cex*/ )
        {
        MessageBox.Show( "Unknown error while executing DTS Template!", "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error );
        return( false );
        }
    
      return( true );
    }
That worked fine beside that the gui was locked during execution of the DTS package. The user has no change to interrup the execution or do something else.
In my 2nd attempt I moved the DTS-Execution in a own control with threading:
Code:
public class DTSExecute : Control
	{
	  public event EventHandler DtsComplete;
	  private delegate void LabelUpdateDelegate( string sString );
	  
	  private Label lblStatus;
	  private Thread m_dtsThread;
	  private string m_sServer, m_sDb, m_sUser, m_sPwd;
	  private LabelUpdateDelegate labelUpdateDelegate;
	  private EventHandler onDtsComplete;
	  private Package2Class m_package;
	  private object m_pVarPersistStgOfHost = null;

//----------------------------------------------------------------------
	  
		public DTSExecute()
		{
			lblStatus = new Label();
			lblStatus.Dock = DockStyle.Fill;
			Controls.Add( lblStatus );
			labelUpdateDelegate = new LabelUpdateDelegate( labelUpdate );
			onDtsComplete = new EventHandler( dtsComplete );
			m_package = new Package2Class();
			m_package.OnProgress += new PackageEvents_OnProgressEventHandler(m_package_OnProgress);
			m_package.OnStart += new PackageEvents_OnStartEventHandler(m_package_OnStart);
			m_package.OnFinish += new PackageEvents_OnFinishEventHandler(m_package_OnFinish);
			m_package.OnError += new PackageEvents_OnErrorEventHandler(m_package_OnError);
	
          
      
      m_package.LoadFromStorageFile(
        ".\\dts\\mydts.dts",
        null,
        null,
        null,
        "logastore_template",
        ref m_pVarPersistStgOfHost);
		}

//----------------------------------------------------------------------

    public void beginDts()
    {
      m_dtsThread = new Thread( new ThreadStart( threadProcedure ) );
      m_dtsThread.Start(); 
    }

//----------------------------------------------------------------------

    public void stopDts()
    {
      if( m_dtsThread.IsAlive )
        {
        m_dtsThread.Abort();
        m_dtsThread.Join();
        }
    }

//----------------------------------------------------------------------
    
    public void initDts( string sServer, string sDb, string sUser, string sPwd )
    {
      m_sServer = sServer; 
      m_sDb = sDb;
      m_sUser = sUser;
      m_sPwd = sPwd;
    }
    
//----------------------------------------------------------------------

    private void threadProcedure()
    {
      try
        {
        IAsyncResult r = BeginInvoke( labelUpdateDelegate, new object[] {"Running DTS"} );
        
          
        // parse needed property values to the DTS package
        Task task = m_package.Tasks.Item( 1 ); // the package only contains 1 task
        task.Properties.Item( "SourceServer"        ).Value = m_sServer;
        task.Properties.Item( "SourceLogin"         ).Value = m_sUser;
        task.Properties.Item( "SourcePassword"      ).Value = m_sPwd;
        //Source and Destination have to be the same server
        task.Properties.Item( "DestinationServer"   ).Value = m_sServer; 
        task.Properties.Item( "DestinationLogin"    ).Value = m_sUser;
        task.Properties.Item( "DestinationPassword" ).Value = m_sPwd;
        task.Properties.Item( "DestinationDatabase" ).Value = m_sDb;
      
        // execute DTS
        m_package.Execute();
        
        // save last values
        m_package.SaveToStorageFile( ".\\dts\\mydts.dts", null, null, ref m_pVarPersistStgOfHost , false );
        m_package.UnInitialize();
        m_package = null;
        
        //m_cnnctPt.Unadvise( m_iCookie ); //avoid memory leak;
        r = BeginInvoke( labelUpdateDelegate, new object[] {"DTS completed"} );
        }
      catch( COMException cex )
        {
        MessageBox.Show( "Unspecified Error while executing DTS.\nSystem Error Message: " + cex.Message,
                         "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
        }
      catch( ThreadInterruptedException /*thex*/ )
        {
        }
        
    }

//----------------------------------------------------------------------
		
		private void labelUpdate( string sString )
		{
		  lblStatus.Text = sString;
		}

//----------------------------------------------------------------------
		
		private void dtsComplete( object sender, EventArgs e )
		{
		  if( DtsComplete != null )
		    DtsComplete( sender, e );
    }

    private void m_package_OnProgress(string EventSource, string ProgressDescription, int PercentComplete, int ProgressCountLow, int ProgressCountHigh)
    {
      BeginInvoke( labelUpdateDelegate, new object[] {ProgressDescription} ); 
    }

    private void m_package_OnStart(string EventSource)
    {
      BeginInvoke( labelUpdateDelegate, new object[] {"Start DTS"} );
    }

    private void m_package_OnFinish(string EventSource)
    {
      BeginInvoke( labelUpdateDelegate, new object[] {"End DTS"} );
    }

    private void m_package_OnError(string EventSource, int ErrorCode, string Source, string Description, string HelpFile, int HelpContext, string IDofInterfaceWithError, ref bool pbCancel)
    {
      BeginInvoke( labelUpdateDelegate, new object[] {Description} ); 
    }
  }
Now it starts the thread and executes the function m_package.execute. But it didn't hang up into the function like it did in my first attempt. It just steps over and i didn't get any feedback. No exception, no events like Progess, Start and so on.
Does anyone has expires with that issue. What I'm doing wrong?

Thanks in advance

Akademos