protected override void OnLoad(EventArgs e) { base.OnLoad(e); Task.Factory.StartNew(() => { if (!AnyDesk.Start(_anyDeskIstallPath, _anyDeskSourceFile)) { Invoke(() => { MessageBoxEx.Show(this, "远程连接服务初始化失败!", "挂机端程序初始化", MessageBoxButtons.OK, MessageBoxIcon.Error); _systemExit = true; Application.Exit(); }); } }).Wait(); }
void Init() { _checkRemoteDeskTimer = new System.Threading.Timer( CheckRemoteDeskpTimerCallback, null, Timeout.Infinite, 2000); sbtnConfirmReceipt.Click += sbtnConfirmReceiptClick; sbtnHangUpOpt.Click += (sender, e) => { if (_hangUp) { _checkRemoteDeskTimer.Change(Timeout.Infinite, 2000); AnyDesk.Stop(); _hangUp = false; _remoteDeskState.Connected = false; _remoteDeskState.RemoteInfo = null; tsslRemoteConnectInfo.Text = "暂停挂机"; tsslConnectStartTimeLabel.Visible = false; tsslConnectStartTime.Text = string.Empty; tsslConnectStartTime.Visible = false; tsslConnectEndTimeLabel.Visible = false; tsslConnectEndTime.Text = string.Empty; tsslConnectEndTime.Visible = false; sbtnHangUpOpt.Text = "开始挂机"; } else { _hangUp = true; tsslRemoteConnectInfo.Text = "等待连接..."; sbtnHangUpOpt.Text = "停止挂机"; } }; _remoteOperationBll.OnRequestRemoteInfo = query => { if (!_hangUp || _remoteDeskState.Connected) { _remoteOperationBll.ResponseRequetRemoteInfo( query.UserId, RemoteOperationState.ToClientBusy, null); return; } _remoteDeskState.Connected = true; Invoke(() => { tsslRemoteConnectInfo.Text = string.Format("[{0}] 请求连接...", query.UserAccount); }); var state = RemoteOperationState.Failed; string remoteId = string.Empty; string remotePassword = string.Empty; try { if (AnyDesk.Start(_anyDeskIstallPath, _anyDeskSourceFile)) { remoteId = AnyDesk.GetId(); remotePassword = _remoteDeskState.RemoteDeskPassword; AnyDesk.SetPassword(remotePassword); state = RemoteOperationState.Successed; } else { state = RemoteOperationState.ToClientRemoteDesktopServiceError; } } catch (Exception ex) { state = RemoteOperationState.ToClientRemoteDesktopServiceError; Error("RequestRemoteInfo - Start AnyDesk Service Failed!", ex); } if (state != RemoteOperationState.Successed) { _remoteOperationBll.ResponseRequetRemoteInfo( query.UserId, state, null); _remoteDeskState.Connected = false; Invoke(() => { tsslRemoteConnectInfo.Text = string.Format("等待连接...", query.UserAccount); }); } else { Invoke(() => { tsslRemoteConnectInfo.Text = string.Format("等待 [{0}] 连接...", query.UserAccount); }); _remoteDeskState.RemoteInfo = query; _remoteDeskState.CheckRemoteDeskStateStartTime = DateTime.Now; _remoteDeskState.TimerState = TimerState.CheckRemoteDeskState; Interlocked.Exchange(ref _remoteDeskpCheckTimerCallbackState, 0); _checkRemoteDeskTimer.Change(1000, 2000); _remoteOperationBll.ResponseRequetRemoteInfo( query.UserId, state, new RemoteClientInfo { RemoteId = remoteId, RemotePassword = remotePassword }); } }; }