インストールプロセスの特定のポイントに達するとポップアップするフォームを追加しようとしているインストーラーがあります。
このフォームは、インストールの一部の場所として使用する目的のフォルダーの場所を取得するために使用されます。フォームは正常に表示され、フォルダーの場所を手動で入力すると機能します。しかし、どのユーザーがこれを手動で行う必要があるでしょうか? そのため、フォルダーダイアログとして機能するボタンを追加しましたが、これをクリックするとスレッドステート例外が発生します。
この問題を調査した結果、これが発生する最も一般的な理由は、プログラムのメイン メソッドに [stathread] がないためです。これはすでにインストーラーに追加されているので、Winformsは私が多くの時間を費やしたものではないため、これで何が間違っているのかを誰かが教えてくれることを望んでいました.
これが、この特定の問題で使用しているコードです。
フォームを開くための呼び出し。
OracleDriveLocations ODL = new OracleDriveLocations();
ODL.ShowDialog();
フォルダー ダイアログ ボタンのコード。
this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
this.folderBrowserDialog1.ShowNewFolderButton = true;
DialogResult rst = this.folderBrowserDialog1.ShowDialog();
if (rst == DialogResult.OK)
{
string path = this.folderBrowserDialog1.SelectedPath;
logger.DebugFormat("Data Files path was changed to {0}.", path);
this.DataFileLocationTB.Text = path;
}
私はまた、これを実行するために一時スレッドを使用しようとしましたが、それ自体は役に立ちませんでした:
var t = new Thread((ThreadStart)(() =>
{
this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
this.folderBrowserDialog1.ShowNewFolderButton = true;
DialogResult rst = this.folderBrowserDialog1.ShowDialog();
if (rst == DialogResult.OK)
{
string path = this.folderBrowserDialog1.SelectedPath;
logger.DebugFormat("Data Files path was changed to {0}.", path);
this.DataFileLocationTB.Text = path;
}
}));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
要求されたスタック トレース
at System.Windows.Forms.FolderBrowserDialog.RunDialog(IntPtr hWndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
at DM.Installer.OracleDriveLocations.DataFilesButton_Click(Object sender, EventArgs e) in C:\Users\Administrator\Desktop\PIDirect_Access\Installer\PIDirectAccessInstaller64Bit
- try 2\DM.Installer\OracleDriveLocations.cs:line 51
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at DM.Installer.SchemaHandler.Install(BackgroundWorker worker, DoWorkEventArgs e, InstallerData data) in C:\Users\Administrator\Desktop\PIDirect_Access\Installer\PIDirectAccessInstaller64Bit
- try 2\DM.Installer\SchemaHandler.cs:line 100
at DM.Installer.InstallProgressPage.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in C:\Users\Administrator\Desktop\PIDirect_Access\Installer\PIDirectAccessInstaller64Bit
- try 2\DM.Installer\InstallProgressPage.cs:line 404
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
私が間違っていることについての助けや提案は大歓迎です。ありがとうございました。