multithreading - switch / create desktop C# opening form inside -


hi there have been working on program long time goal have lock system switch between desktops login form on 2nd screen allow login have run problem can not login from2 close second desktop can destroyed have manually close have tried invoking close , hide have tried destroy process not close not close. if use method .showdialog open form if use .show . close form parts of work show blank windows

form1 main form process request

        public form1()         {             initializecomponent();             // create thread object. not start thread.             worker workerobject = new worker();             thread workerthread = new thread(workerobject.dowork);              workerthread.start();             system.threading.thread.sleep(3000);             workerobject.requeststop();          }      }       public partial class worker     {             static desctop mdesktop = new desctop();          // method called when thread started.          public  void dowork()         {              mdesktop.createnewdesktop("mayshotspot");             using (form2 frm = new form2())             {                  frm.showdialog();                 while (!_shouldstop) { }                 frm.close(); // not close form              }              mdesktop.destroydesktop();             mdesktop.destroyproces();             }          public void requeststop()         {             _shouldstop = true;         }         // volatile used hint compiler data          // member accessed multiple threads.          private volatile bool _shouldstop;        }     } 

screen switch class

        static string desktopname = "mayshotspot";         arraylist list = new arraylist();         public  bool needbootstrapping()         {             return (getdesktopname() == desktopname);         }         public static string getdesktopname()         {             int dlength = 0, dhandle = getthreaddesktop(getcurrentthreadid());             stringbuilder dname = new stringbuilder();             getuserobjectinformation(dhandle, uoi_name, dname, 0, ref dlength);             if (dlength != 0) getuserobjectinformation(dhandle, uoi_name, dname, dlength, ref dlength);             return (dname.tostring());         }          public void createnewdesktop(string desktopname)         {             getthreaddesktop(getcurrentthreadid());             openinputdesktop(0, false, desktop_switchdesktop);             int desktophandle = createdesktop(desktopname, "", 0, 0, generic_all, 0);             setthreaddesktop(desktophandle);             switchdesktop(desktophandle);         }         public void destroydesktop()         {             createnewdesktop("default");         }          public process startprocess(string path)         {             process_information pi = new process_information();             startupinfo si = new startupinfo();             si.cb = marshal.sizeof(si);             si.lpdesktop = desktopname;             bool result = createprocess(null, path, intptr.zero, intptr.zero, true, normal_priority_class, intptr.zero, null, ref si, ref pi);             if (result)             {                 // waitforsingleobject(pi.hprocess, infinite);                 // closehandle(pi.hprocess);                 //closehandle(pi.hthread);                 list.add(pi.dwprocessid);                 return process.getprocessbyid(pi.dwprocessid);             }             else             {                 destroydesktop();                 return null;             }         }          public void setprocesspriorityhigh()         {             setthreadpriority(getcurrentthread(), thread_base_priority_max);             setpriorityclass(getcurrentprocess(), realtime_priority_class);         }          public void exitproces(int uexitcode)         {             // exitprocess(uexitcode);             process.getprocessbyid(uexitcode).kill();         }         public void destroyproces()         {             process thisproc = process.getcurrentprocess();             foreach (int p in list)             {                 try                 {                     process.getprocessbyid(p).kill();                 }                 catch (exception ex)                 {                  }             }         }          public void exitproces()         {             exitprocess(0);         } 

form 2 - login screen appear the desktop switch left default @ moment till can find why not close


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -