I've done a few .Net applications before but this is my first time with an installer.
My installer puts a file (.esriAddIn extension - essentially a zip archive that is unpacked to the user's home directory by an ESRI product when executed) on the user's filesystem and then attempts to execute that开发者_如何学JAVA file after the installer has finished.
However it seems that the installer is still accessing my file by the time it is executed, and the process fails with the message "...file may be in use..."
I've tried executing the process in the overridden OnCommitted function, in a Committed event handler and a couple of other places but no joy.
Can anyone tell me how to execute the file at a time when the installer isn't keeping hold of it?
Installer class currently looks like this:
protected override void OnCommitted(IDictionary savedState)
{
base.OnCommitted(savedState);
string installFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string addinFile = @"\<<file name>>.esriAddIn";
System.Diagnostics.Process.Start(installFolder + addinFile);
}
Any help much appreciated.
If anyone is interested in did manage to solve this and no great mastery was involved. I guess I just never tried this combination previously:
public partial class Installer : System.Configuration.Install.Installer
{
private string m_addInLocation;
public Installer()
{
InitializeComponent();
this.Committed += new InstallEventHandler(this.onCommit);
}
protected override void OnCommitted(IDictionary savedState)
{
this.m_addInLocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\<<add-in name>>.esriAddIn";
// raise the committed event - ensure this happens after add in location has been determined
base.OnCommitted(savedState);
}
private void onCommit(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start(this.m_addInLocation);
}
catch (Exception) { MessageBox.Show("..."); }
}
}
精彩评论