どうすればスレッドを分離できますか?
最初にインスタンスを使用してLoginForm.csを実行したので、アプリの最初のスレッドはLoginForm.csファイルですが、LoginForm.csのスレッドを実行したくありません。ログインに成功したら、アプリでメインスレッドを実行します。 MainInterface.cs、つまり、最初にスレッドがLoginForm.csを実行し、次にLoginForm.csでスレッドを停止します。ログインが修正された後、スレッドはMainInterface.csで実行されます。
以下のコードが続きましたが、LoginForm.csはまだメインスレッドです:
MainInterface.cs
using System;
public class MainInterface : Form
{
private static MainInterface Current;
private MainInterface ()
{
if ( LoginForm.Instance != null )
LoginForm.Instance.Close ();
}
public static MainInterface Instance
{
get
{
if (Current == null)
{
Current = new MainInterface ();
}
return Current;
}
}
}
LoginForm.cs
using System;
public class LoginForm: Form
{
private static LoginForm Current;
private LoginForm ()
{
if ( MainInterface.Instance != null )
MainInterface.Instance.Close ();
}
public static LoginForm Instance
{
get
{
if (Current == null)
{
Current = new LoginForm ();
}
return Current;
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Myapp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginForm.Instance.ShowDialog ();
}
}
}