winforms - How to switch Mainthread in C# Application -


how can separate thread?

i used instance run loginform.cs firstly, so, first thread in app loginform.cs file,but don't want run loginform.cs's thread anymore, after login successfull, want app run main thread in maininterface.cs, meaning that, first thread run loginform.cs, stop thread on loginform.cs, after logined corrected, thread running in maininterface.cs.

i follow below code, loginform.cs still main thread:

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    {              {          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    {              {          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>         /// main entry point application.         /// </summary>         [stathread]         static void main()         {              application.enablevisualstyles();             application.setcompatibletextrenderingdefault(false);             loginform.instance.showdialog ();          }     } } 

program.cs

using (login login = new login())         {              login.showdialog(); //close form after login correct in login form button_click         }         if (isvaliduser == true) //static variable created in application check user         {                         application.run(new maininterface());          } 

login form click event

    private void btnlogin_click(object sender, eventargs e)             {               if(isvaliduser == true)                {                   this.close();                }              else                {                   //else part code                }             } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -