internal RdpClient(ContainerControl parent, Size size, EventHandler resizeHandler) { this.parent = parent; this.size = size; try { rdpControl = rdpClient9 = new MsRdpClient9(); RDPConfigure(size); //add event handler for when RDP display is resized rdpClient9.OnRemoteDesktopSizeChange += rdpClient_OnRemoteDesktopSizeChange; // CA-96135: Try adding rdpControl to parent.Controls list; this will throw exception when // MsRdpClient8 control cannot be created (there is no appropriate version of dll present) parent.Controls.Add(rdpControl); allowDisplayUpdate = true; needsRdpVersionWarning = false; } catch { //any problems: fall back without thinking too much if (parent.Controls.Contains(rdpControl)) { parent.Controls.Remove(rdpControl); } rdpClient9 = null; rdpControl = rdpClient6 = new MsRdpClient6(); RDPConfigure(size); parent.Controls.Add(rdpControl); needsRdpVersionWarning = true; } rdpControl.Resize += resizeHandler; }
internal RdpClient(ContainerControl parent, Size size, EventHandler resizeHandler) { this.parent = parent; this.size = size; try { rdpClient = new MsRdpClient9(); RDPConfigure(size); //add event handler for when RDP display is resized rdpClient.OnRemoteDesktopSizeChange += rdpClient_OnRemoteDesktopSizeChange; rdpClient.Resize += resizeHandler; // CA-96135: Try adding rdpControl to parent.Controls list; this will throw exception when // MsRdpClient9 control cannot be created (there is no appropriate version of dll present) parent.Controls.Add(rdpClient); allowDisplayUpdate = true; } catch (Exception ex) { if (parent.Controls.Contains(rdpClient)) { parent.Controls.Remove(rdpClient); } rdpClient.Dispose(); rdpClient = null; Log.Error("Adding rdpControl to parent.Controls list caused an exception.", ex); } }
public void Connect(string rdpIP) { try { RDPSetSettings(); } catch (Exception ex) { if (parent.Controls.Contains(rdpClient)) { parent.Controls.Remove(rdpClient); } rdpClient.Dispose(); rdpClient = null; Log.Error("Setting the RDP client properties caused an exception.", ex); } RDPConnect(rdpIP, size.Width, size.Height); }
public void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (rdpClient != null) { // We need to dispose the rdp control. However, doing it immediately (in the control's own // OnDisconnected event) will cause a horrible crash. Instead, start a timer that will // call the dispose method on the GUI thread at the next available opportunity. CA-12902 Timer t = new Timer(); t.Tick += delegate { try { Log.Debug("RdpClient Dispose(): rdpControl.Dispose() in delegate"); rdpClient.Dispose(); } catch (Exception) { // We often get NullReferenceException here } t.Stop(); RdpCleanupTimers.Remove(t); Log.Debug("RdpClient Dispose(): Timer stopped and removed in delegate"); }; t.Interval = 1; RdpCleanupTimers.Add(t); Log.DebugFormat("RdpClient Dispose(): Start timer (timers count {0})", RdpCleanupTimers.Count); t.Start(); } else { Log.Debug("RdpClient Dispose(): rdpControl == null"); } } rdpClient = null; Log.Debug("RdpClient Dispose(): disposed = true"); disposed = true; } }