This documentation is archived and is not being maintained.

InstallEventArgs Class

Provides data for the events: BeforeInstall, AfterInstall, Committing, Committed, BeforeRollback, AfterRollback, BeforeUninstall, AfterUninstall.

For a list of all members of this type, see InstallEventArgs Members.

System.Object
   System.EventArgs
      System.Configuration.Install.InstallEventArgs

[Visual Basic]
Public Class InstallEventArgs
   Inherits EventArgs
[C#]
public class InstallEventArgs : EventArgs
[C++]
public __gc class InstallEventArgs : public EventArgs
[JScript]
public class InstallEventArgs extends EventArgs

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

InstallEventArgs contains an IDictionary that holds information about the current state of the installation. The BeforeInstall, AfterInstall, Committing, Committed, BeforeRollback, AfterRollback, BeforeUninstall, and AfterUninstall event handlers use this information.

Example

[Visual Basic, C#, C++] The following example demonstrates the InstallEventArgs constructors and the SavedState property of the InstallEventArgs class.

[Visual Basic, C#, C++] There are two new events called BeforeCommit and AfterCommit. The handlers of these events are invoked from the protected methods named OnBeforeCommit and OnAfterCommit respectively. These events are raised when the Commit method is called.

[Visual Basic] 
Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Configuration.Install
Imports System.IO
Imports Microsoft.VisualBasic

<RunInstaller(True)> Public Class MyInstaller
   Inherits Installer
   ' Simple events to handle before and after commit handlers.
   Public Event BeforeCommit As InstallEventHandler
   Public Event AfterCommit As InstallEventHandler

   Public Sub New()
      ' Add handlers to the events.
      AddHandler BeforeCommit, AddressOf BeforeCommitHandler
      AddHandler AfterCommit, AddressOf AfterCommitHandler
   End Sub

   Public Overrides Sub Install(savedState As IDictionary)
      MyBase.Install(savedState)
      Console.WriteLine("Install ..." + ControlChars.Newline)
   End Sub

   Public Overrides Sub Commit(savedState As IDictionary)
      Console.WriteLine("Before Committing ..." + ControlChars.Newline)
      ' Call the 'OnBeforeCommit' protected method.
      OnBeforeCommit(savedState)
      MyBase.Commit(savedState)
      Console.WriteLine("Committing ..." + ControlChars.Newline)
      ' Call the 'OnAfterCommit' protected method.
      OnAfterCommit(savedState)
      Console.WriteLine("After Committing ..." + ControlChars.Newline)
   End Sub

   Public Overrides Sub Rollback(savedState As IDictionary)
      MyBase.Rollback(savedState)
      Console.WriteLine("RollBack ..." + ControlChars.Newline)
   End Sub

   Public Overrides Sub Uninstall(savedState As IDictionary)
      MyBase.Uninstall(savedState)
      Console.WriteLine("UnInstall ..." + ControlChars.Newline)
   End Sub

   ' Protected method that invoke the handlers associated with the 'BeforeCommit' event.
   Protected Overridable Sub OnBeforeCommit(savedState As IDictionary)
         RaiseEvent BeforeCommit(Me, New InstallEventArgs(savedState))
   End Sub

   ' Protected method that invoke the handlers associated with the 'AfterCommit' event.
   Protected Overridable Sub OnAfterCommit(savedState As IDictionary)
         RaiseEvent AfterCommit(Me, New InstallEventArgs())
   End Sub

   ' A simple event handler to exemplify the example.
   Private Sub BeforeCommitHandler(sender As Object, e As InstallEventArgs)
      Console.WriteLine("BeforeCommitHandler event handler has been called" + _
                                                      ControlChars.Newline)
      Console.WriteLine("The count of saved state objects are : {0}" + _
                                    ControlChars.Newline, e.SavedState.Count)
   End Sub

   ' A simple event handler to exemplify the example.
   Private Sub AfterCommitHandler(sender As Object, e As InstallEventArgs)
      Console.WriteLine("AfterCommitHandler event handler has been called" + _
                                                      ControlChars.Newline)
   End Sub
End Class

[C#] 

using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;

[RunInstaller(true)]
public class MyInstaller : Installer
{
   // Simple events to handle before and after commit handlers.
   public event InstallEventHandler BeforeCommit;
   public event InstallEventHandler AfterCommit;
   
   public MyInstaller()
   {
      // Add handlers to the events.
      BeforeCommit += new InstallEventHandler(BeforeCommitHandler);
      AfterCommit += new InstallEventHandler(AfterCommitHandler);
   }

   public override void Install(IDictionary savedState)
   {
      base.Install(savedState);
      Console.WriteLine("Install ...\n");
   }

   public override void Commit(IDictionary savedState)
   {
      Console.WriteLine("Before Committing ...\n");
      // Call the 'OnBeforeCommit' protected method.
      OnBeforeCommit(savedState);
      base.Commit(savedState);
      Console.WriteLine("Committing ...\n");
      // Call the 'OnAfterCommit' protected method.
      OnAfterCommit(savedState);
      Console.WriteLine("After Committing ...\n");
   }

   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
      Console.WriteLine("RollBack ...\n");
   }

   public override void Uninstall(IDictionary savedState)
   {
      base.Uninstall(savedState);
      Console.WriteLine("UnInstall ...\n");
   }
   
   // Protected method that invoke the handlers associated with the 'BeforeCommit' event.
   protected virtual void OnBeforeCommit(IDictionary savedState)
   {
      if(BeforeCommit != null)
         BeforeCommit(this, new InstallEventArgs(savedState)); 
   }

   // Protected method that invoke the handlers associated with the 'AfterCommit' event.
   protected virtual void OnAfterCommit(IDictionary savedState)
   {
      if(AfterCommit != null)
         AfterCommit(this, new InstallEventArgs());
   }

   // A simple event handler to exemplify the example.
   private void BeforeCommitHandler(Object sender, InstallEventArgs e)
   {
      Console.WriteLine("BeforeCommitHandler event handler has been called\n");
      Console.WriteLine("The count of saved state objects are : {0}\n",
         e.SavedState.Count);
   }

   // A simple event handler to exemplify the example.
   private void AfterCommitHandler(Object sender, InstallEventArgs e)
   {
      Console.WriteLine("AfterCommitHandler event handler has been called\n");
   }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Configuration::Install;
using namespace System::IO;

[RunInstaller(true)]
__gc class MyInstaller : public Installer {
public:
    // Simple events to handle before and after commit handlers.
    __event InstallEventHandler* BeforeCommit;
    __event InstallEventHandler* AfterCommit;

    MyInstaller() {
        // Add handlers to the events.
        BeforeCommit += new InstallEventHandler(this, &MyInstaller::BeforeCommitHandler);
        AfterCommit += new InstallEventHandler(this, &MyInstaller::AfterCommitHandler);
    }

    void Install(IDictionary* savedState) {
        Installer::Install(savedState);
        Console::WriteLine(S"Install ...\n");
    }

    void Commit(IDictionary* savedState) {
        Console::WriteLine(S"Before Committing ...\n");
        // Call the 'OnBeforeCommit' protected method.
        OnBeforeCommit(savedState);
        Installer::Commit(savedState);
        Console::WriteLine(S"Committing ...\n");
        // Call the 'OnAfterCommit' protected method.
        OnAfterCommit(savedState);
        Console::WriteLine(S"After Committing ...\n");
    }

    void Rollback(IDictionary* savedState) {
        Installer::Rollback(savedState);
        Console::WriteLine(S"RollBack ...\n");
    }

    void Uninstall(IDictionary* savedState) {
        Installer::Uninstall(savedState);
        Console::WriteLine(S"UnInstall ...\n");
    }

protected:
    // Protected method that invoke the handlers associated with the 'BeforeCommit' event.
    virtual void OnBeforeCommit(IDictionary* savedState) {
        if (BeforeCommit)
            BeforeCommit(this, new InstallEventArgs(savedState));
    }

    // Protected method that invoke the handlers associated with the 'AfterCommit' event.
    virtual void OnAfterCommit(IDictionary* savedState) {
        if (AfterCommit)
            AfterCommit(this, new InstallEventArgs());
    }

    // A simple event handler to exemplify the example.
    void BeforeCommitHandler(Object* sender, InstallEventArgs* e) {
        Console::WriteLine(S"BeforeCommitHandler event handler has been called\n");
        Console::WriteLine(S"The count of saved state objects are : {0}\n",
            __box(e->SavedState->Count));
    }

    // A simple event handler to exemplify the example.
    void AfterCommitHandler(Object* sender, InstallEventArgs* e) {
        Console::WriteLine(S"AfterCommitHandler event handler has been called\n");
    }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Configuration.Install

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Configuration.Install (in System.Configuration.Install.dll)

See Also

InstallEventArgs Members | System.Configuration.Install Namespace | AfterInstall | AfterRollback | AfterUninstall | BeforeInstall | BeforeRollback | BeforeUninstall | Commit | Committed | Committing | Install | Installer | InstallEventHandler | Rollback | Uninstall

Show: