private void RestoreAppToInitialState(string message, bool doWait) { if (doWait) { Thread.Sleep(1000); } if (TCH != null) { TCH.StopServer(); TCH.Dispose(); TCH = null; } disposed = false; hostOrClient = true; NativeMethods.ClipCursor(IntPtr.Zero); EnableWindowControls(); Komputer[] comps = { (Komputer)vb1.Child, (Komputer)vb2.Child, (Komputer)vb3.Child }; StopBlinking(comps); bottomLabel.Content = message; if ((bool)this.edgesConnCB.IsChecked) { edgeCheckerTimer.Start(); } if (localIPLabel.Content.ToString() != null) { ServerSideProcedure(); } }
private void ServerSideProcedure() { // Stopping client side: if (connMaker != null && connMaker.IsAlive && !hostOrClient) { mainTimer.Stop(); connMaker.Abort(); while (connMaker.IsAlive) { Thread.Sleep(1000); } connMaker = null; TCH = null; GC.Collect(); } hostOrClient = true; if (TCH == null) { TCH = new TwoCursorsHandlerImpl(localIPLabel.Content.ToString(), timeWin, hostOrClient); } connMaker = new Thread(TCH.MakeConnection); connMaker.IsBackground = true; connMaker.Start(); pasteChecker = new Thread(CheckPaste); pasteChecker.IsBackground = true; pasteChecker.SetApartmentState(ApartmentState.STA); pasteChecker.Start(); mainTimer.Start(); }
private void ClientSideProcedure(byte computerTag) { // Stopping server side: if (connMaker != null && connMaker.IsAlive && hostOrClient) { mainTimer.Stop(); connMaker.Abort(); while (connMaker.IsAlive) { Thread.Sleep(1000); } connMaker = null; TCH = null; GC.Collect(); } if (TCH == null) { // Locking mouse cursor in the window: Point lockingRect = this.PointToScreen(new Point(0, 0)); System.Drawing.Rectangle r = new System.Drawing.Rectangle( (int)lockingRect.X, (int)lockingRect.Y, (int)(lockingRect.X + this.Width - 16 * SystemParameters.BorderWidth), (int)(lockingRect.Y + this.Height - 2 * SystemParameters.WindowCaptionHeight)); NativeMethods.ClipCursor(ref r); hostOrClient = false; DisableWindowControls(); List <Komputer> comps = new List <Komputer>(); comps.Add((Komputer)vb2.Child); string ip = ""; switch (computerTag) { case 0: ip = leftCompIPTB.Text; comps.Add((Komputer)vb1.Child); break; case 1: ip = rightCompIPTB.Text; comps.Add((Komputer)vb3.Child); break; } TCH = new TwoCursorsHandlerImpl(ip, timeWin, hostOrClient); connMaker = new Thread(TCH.MakeConnection); connMaker.IsBackground = true; connMaker.Start(); mainTimer.Start(); StartBlinking(comps); this.bottomLabel.Content = "Trwa próba połączenia z hostem."; } }