c# - VNCSharp remote desktop null reference on disconnect -


i have program allows users log entire computer lab automatically using vncsharp. after code reorganization running issue cant seem solve. following method logs computer after vnc connection has been established.

        private void rd_connectcomplete_1(object sender, connecteventargs e)        {         if (action == labloginaction.login)         {             //give remote desktop control focus             rd.focus();              //send control alt delete             rd.sendspecialkeys(specialkeys.ctrlaltdel);              //wait 1/2 second             system.threading.thread.sleep(500);              //run through secure windows user name string             foreach (char c in converttounsecurestring(windowsusername))             {                 //type each key, wait 1ms                 sendkeys.sendwait(c.tostring());                 system.threading.thread.sleep(1);             }              //send tab key press             sendkeys.sendwait("{tab}");              //run through secure windows password string             foreach (char c in converttounsecurestring(windowspassword))             {                 //type each key, wait 1ms                 sendkeys.sendwait(c.tostring());                 system.threading.thread.sleep(1);             }              //send enter key press             sendkeys.sendwait("{enter}");              //wait 1ms             system.threading.thread.sleep(1);              //disconect remote computer             rd.disconnect();         }     } 

this method logs computer in however, once rd.disconnect() called @ end, throws null reference exception. rd object represents vncsharp remotedesktop control have on form. how throwing null reference exception when calling disconnect method, not when used in method?

as evan l suggested there 2 properties null used in remotedesktop disconnect method. somehow, not getting initialized until after disconnect method called. both of these objects had worker thread used incoming updates server. however, application need login computer, disconnect , move on next machine. therefore have no need of updates kind of desktop control. modified code not try , stop thread, doesn't exist yet.

public void disconnect()     {         // stop worker thread.         if (done != null)         {             done.set();         }          // bug fix: simon.phillips@warwick.ac.uk ultravnc disconnect issue         // request tiny screen update flush blocking read         try {             rfb.writeframebufferupdaterequest(0, 0, 1, 1, false);         } catch {             // may not work, disconnect can called in response             // vncclient raising connectionlost event (e.g., remote host died).         }          if (worker != null)         {             worker.join(3000);  // number arbitrary, doesn't block forever....         }          rfb.close();             rfb = null;     } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -