共用方式為


AssemblyInstaller.Commit(IDictionary) 方法

定義

完成安裝異動。

public:
 override void Commit(System::Collections::IDictionary ^ savedState);
public override void Commit (System.Collections.IDictionary savedState);
override this.Commit : System.Collections.IDictionary -> unit
Public Overrides Sub Commit (savedState As IDictionary)

參數

savedState
IDictionary

IDictionary,包含安裝程式集合中的所有安裝程式都執行過之後的電腦狀態。

例外狀況

savedState 參數為 null

-或-

IDictionary 的儲存狀態可能已經損毀。

-或-

無法找到檔案。

在集合中有一個安裝程式的 Committing 事件處理常式發生錯誤。

-或-

在集合中有一個安裝程式的 Committed 事件處理常式發生錯誤。

-或-

在安裝的 Commit(IDictionary) 階段時發生例外狀況。 例外狀況會被忽略,安裝會繼續進行。 不過,安裝完成之後,應用程式可能無法正常運作。

-或-

在其中一個組件中無法找到安裝程式型別。

-或-

無法建立其中一個安裝程式型別的執行個體。

在安裝的 Commit(IDictionary) 階段時發生例外狀況。 例外狀況會被忽略,安裝會繼續進行。 不過,安裝完成之後,應用程式可能無法正常運作。

範例

下列範例示範 類別的AssemblyInstallerAssemblyInstaller構函式和 InstallCommit 方法。

AssemblyInstaller 用建 AssemblyInstaller 構函式會建立類別。 會設定這個 物件的屬性, Install 並呼叫 和 Commit 方法來安裝 MyAssembly_Install.exe 元件。

#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Configuration::Install;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
   IDictionary^ mySavedState = gcnew Hashtable;
   Console::WriteLine( "" );
   try
   {
      // Set the commandline argument array for 'logfile'.
      array<String^>^myString = {"/logFile=example.log"};
      
      // Create an Object* of the 'AssemblyInstaller' class.
      AssemblyInstaller^ myAssemblyInstaller = gcnew AssemblyInstaller;

      // Set the properties to install the required assembly.
      myAssemblyInstaller->Path = "MyAssembly_Install.exe";
      myAssemblyInstaller->CommandLine = myString;
      myAssemblyInstaller->UseNewContext = true;
      
      // Clear the 'IDictionary' Object*.
      mySavedState->Clear();
      
      // Install the 'MyAssembly_Install' assembly.
      myAssemblyInstaller->Install( mySavedState );
      
      // Commit the 'MyAssembly_Install' assembly.
      myAssemblyInstaller->Commit( mySavedState );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e );
   }
}
using System;
using System.Configuration.Install;
using System.Collections;
using System.Collections.Specialized;

class MyInstallClass
{
   static void Main()
   {
      IDictionary mySavedState = new Hashtable();

      Console.WriteLine( "" );

      try
      {
         // Set the commandline argument array for 'logfile'.
         string[] myString = new string[ 1 ];
         myString[ 0 ] = "/logFile=example.log";

         // Create an object of the 'AssemblyInstaller' class.
         AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();

         // Set the properties to install the required assembly.
         myAssemblyInstaller.Path = "MyAssembly_Install.exe";
         myAssemblyInstaller.CommandLine = myString;
         myAssemblyInstaller.UseNewContext = true;

         // Clear the 'IDictionary' object.
         mySavedState.Clear();

         // Install the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Install( mySavedState );

         // Commit the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Commit( mySavedState );
      }
      catch( Exception )
      {
      }
   }
}
Imports System.Configuration.Install
Imports System.Collections
Imports System.Collections.Specialized

Class MyInstallClass
   
   Shared Sub Main()
      Dim mySavedState = New Hashtable()
      
      Console.WriteLine("")
      

      Try
         ' Set the commandline argument array for 'logfile'.
         Dim myString(0) As String
         myString(0) = "/logFile=example.log"
         ' Create an object of the 'AssemblyInstaller' class.
         Dim myAssemblyInstaller As New AssemblyInstaller()
         ' Set the properties to install the required assembly.
         myAssemblyInstaller.Path = "MyAssembly_Install.exe"
         myAssemblyInstaller.CommandLine = myString
         myAssemblyInstaller.UseNewContext = True
         
         ' Clear the 'IDictionary' object.
         mySavedState.Clear()
         
         ' Install the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Install(mySavedState)
         
         ' Commit the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Commit(mySavedState)
      Catch
      End Try

   End Sub
End Class

備註

只有在這個實例InstallerCollection中所有安裝程式的方法都成功時Install,才會呼叫這個方法。 這個方法接著會 Commit 呼叫集合中每個安裝程式的方法。

將可能需要執行正確卸載作業的任何資訊儲存在儲存狀態 IDictionary中,這會傳遞至 Uninstall 方法。

適用於