public void checkDesktopStatus(object param) { ArrayList p = (ArrayList)param; Pool poolSel = (Pool)p[0]; Gateway gw = (Gateway)p[1]; string pixel = (string)p[2]; ListBoxItem poolSelItem = (ListBoxItem)p[3]; string RequestID = (string)p[4]; bool ready = false; //标记桌面是否已准备好 while (!ready) { string status = ""; try { status = serverChannel.getDesktopStatus(ServerIP, RequestID); } catch (Exception e) { logger.Error("为用户" + UserName + "请求桌面状态时产生错误:" + e.Message); updateStatus(poolSelItem, "无法获取桌面状态", false); return; } if (status == null) { //desktopStatus.Text = "没有空闲桌面"; logger.Error("没有空闲桌面可分配给用户" + UserName); updateStatus(poolSelItem, "没有空闲桌面", false); return; } else if (status.Equals("not ready")) { updateStatus(poolSelItem, "桌面正在启动", true); Thread.Sleep(2000); } else { string[] desktop = status.Split(':'); string ip = desktop[0]; int port = Int32.Parse(desktop[1]); bool fullScreen = false; int width = 800; int height = 600; if (pixel.Equals("全屏")) { fullScreen = true; } else { string[] pixelstring = pixel.Split('*'); width = Int32.Parse(pixelstring[0]); height = Int32.Parse(pixelstring[1]); } this.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, (UpdateTheUI) delegate() { //statusBlock.Text = "桌面正在启动..."; //updateStatus("桌面正在启动"); string formTitlePattern = "云晫 - {0}@{1}"; string formTitle = string.Format(formTitlePattern, UserName, poolSel.Name); Thread.Sleep(10000); RemoteDesktopWindow rdw = new RemoteDesktopWindow(formTitle, ip, port, UserName, Password, width, height, fullScreen); if (null != gw) { rdw.setRDGW(gw.getAddress(), gw.getUsername(), gw.getPassword()); } rdw.connect(); rdw.Show(); rdw.BringToFront(); rdpWinList.Add(rdw); ready = true; updateStatus(poolSelItem, "准备", false); }); // 桌面已准备好,开始连接 } } }