//连接服务器 private void connectServer_Button_Click(object sender, RoutedEventArgs e) { superClientSocket.Access(new Action(() => { try { //首先发送自己的Super权限 superClientSocket.Send("SuperUser"); //开始异步接收服务器发送来的消息 superClientSocket.Receive(ReceiveMessageAction); //连接按钮改变一下属性 connectServer_Button.Dispatcher.Invoke(new Action(() => { connectServer_Button.IsEnabled = false; connectServer_Button.Content = "连接中..."; //读取用户信息按钮获取使用权 readUsers_Button.IsEnabled = true; }), null); } catch (Exception) { return; } })); }
//主线程处理的主要事务 private void MainBusinessHandle() { //应用程序管理 processesManageList.BeginManage(); //Socket管理 if (clientSocket.communicateSocket.Connected == false) { //检测是否能够ping通服务器 if (clientSocket.IAccessful()) { clientSocket.Access(new Action(() => { try { //首先发送自己的Mac地址 clientSocket.Send(SystemInfoHelper.GetMacAddress()); //开始异步接收服务器发送来的消息 clientSocket.Receive(ReceiveMessageAction); } catch (Exception) { return; } })); } } }