如何分离线程?
我首先使用实例运行LoginForm.cs,所以,我在应用程序中的第一个线程是LoginForm.cs文件,但我不想再运行LoginForm.cs的线程,登录成功后,我希望我的应用程序运行主线程MainInterface.cs,意思是,首先Thread运行LoginForm.cs,然后在LoginForm.cs上停止Thread,登录更正后,线程运行在MainInterface.cs中。
我跟着下面的代码,但 LoginForm.cs 仍然是一个主线程:
主界面.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;
}
}
}
登录表单.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;
}
}
}
程序.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 ();
}
}
}