Installer.BeforeRollback Event

Definition

Occurs before the installers in the Installers property are rolled back.

C#
public event System.Configuration.Install.InstallEventHandler BeforeRollback;

Event Type

Examples

The following example demonstrates the BeforeRollback event. It overrides the Install method and explicitly throws an ArgumentException so that the Rollback method is called. When the Rollback is complete, the BeforeRollback event occurs and a message is displayed.

C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

// Set 'RunInstaller' attribute to true.
[RunInstaller(true)]
public class MyInstallerClass: Installer
{
   public MyInstallerClass() :base()
   {
      // Attach the 'BeforeRollback' event.
      this.BeforeRollback += new InstallEventHandler(MyInstaller_BeforeRollBack);
      // Attach the 'AfterRollback' event.
      this.AfterRollback += new InstallEventHandler(MyInstaller_AfterRollback);
   }
   // Event handler for 'BeforeRollback' event.
   private void MyInstaller_BeforeRollBack(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("BeforeRollback Event occurred.");
      Console.WriteLine("");
   }
   // Event handler for 'AfterRollback' event.
   private void MyInstaller_AfterRollback(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("AfterRollback Event occurred.");
      Console.WriteLine("");
   }
   // Override the 'Install' method.
   public override void Install(IDictionary savedState)
   {
      base.Install(savedState);
      // Explicitly throw an exception so that roll back is called.
      throw new ArgumentException("Arg Exception");
   }
   // Override the 'Commit' method.
   public override void Commit(IDictionary savedState)
   {
      base.Commit(savedState);
   }
   // Override the 'Rollback' method.
   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
   }
   public static void Main()
   {
      Console.WriteLine("Usage : installutil.exe Installer_BeforeRollback.exe ");
   }
}

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also