私の c# Windows アプリケーションでは、スレッドによってチェックされる条件で別のフォームを表示したいと考えています。その (2 番目の) スレッドは、別の (1 番目の) スレッドによって既に呼び出されています。より良い説明のために使用しているコードは次のとおりです。
主な方法:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Form1 メソッド:
private void Form1_Load(object sender, EventArgs e)
{
// Call First thread to start background jobs.
var thread = new Thread(ThreadFirst);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
// Continue my load event stuff here...
}
private void ThreadFirst()
{
// Do some background operations..
// Call second thread to switch to another background process.
var thread = new Thread(ThreadSecond);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
private void ThreadSecond()
{
If (condition)
// navigate to another form and close running one..
ShowAnotherForm();
else
{
// Continue working on current form.
}
}
[STAThread]
private void ShowAnotherForm()
{
try
{
// Object for new form.
globalForm = new myForm();
globalForm.Show();
// Close the current form running..
this.Close();
this.ShowInTaskbar = false;
Application.Run();
}
catch (Exception ex)
{
messagebox.Show(ex.message);
}
}
私のソリューションからこれを実行しているとき、それは完璧に機能しています。しかし、このための msi パッケージを作成しているときに、両方のフォームが非表示になりました。セットアップからも正常に動作するように、何か追加する必要がありますか?
ありがとう。