-1

どうすればスレッドを分離できますか?

最初にインスタンスを使用して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 ();

        }
    }
}
4

1 に答える 1

0

Program.cs

using (Login login = new Login())
        { 
            login.ShowDialog(); //Close this form after login is correct in login form button_click
        }
        if (isValiduser == true) //Static variable created in application to check user
        {           
             Application.Run(new MainInterface());

        }

ログインフォームクリックイベント

    private void btnLogin_Click(object sender, EventArgs e)
            {
              if(isValiduser == true)
               {
                  this.Close();
               }
             else
               {
                  //else part code
               }
            }
于 2012-06-13T09:40:49.533 に答える