/// <summary> /// This prevents selecting a application in another session from causing /// a temporary select of an incorrect app and the resultant screen updates. /// </summary> /// <summary> /// A session or application node has been selected in the sessions tree. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void sessionsTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { processIsolatedAppUIEvent.Reset(); try { Session session = null; IHostedApplication app; // so we know if this is caused by an agent changing the app with the control // or if this is happening from some other event within CCF. bool hadFocus = sessionsTree.Focused; if (e.Node != null) { session = e.Node.Tag as Session; } if (session != null) { // go to the session selected in the explorer, let it pick which // app is highlighted. sessionManager.SetActiveSession(session.SessionID); } else { // go to the application selected in the session explorer app = e.Node.Tag as IHostedApplication; if (app != null && appsUI != null) { session = e.Node.Parent.Tag as Session; if (session != null) { session.FocusedApplication = app; // so app is selected sessionManager.SetActiveSession(session.SessionID); } // TODO LJZ bool isIsolated = session.AppHost.IsIsolatedApplication(app); bool isExtended = session.AppHost.IsExtendedApplication(app); if (isIsolated || isExtended) { IHostedAppUICommand appUICommand = app as IHostedAppUICommand; if (isIsolated) { FocusIsolatedApplication(appUICommand); } if (isExtended) { appUICommand.ShowForm(); } if (null != SEHostedAppSelected) { SEHostedAppSelected(app, new EventArgs()); } } else { appsUI.SelectApplication(app.ApplicationID); } // Return the focus to the newly selected node if we had the focus // to begin with. if (hadFocus) { sessionsTree.Focus(); } } } } catch (Exception eX) { Logging.Error(localize.SESSION_EXPLORER_MODULE_NAME, eX.Message); } finally { processIsolatedAppUIEvent.Set(); } }
/// <summary> /// Calls the SetFocus() of the isolated hosted application proxy on a different /// thread so that the UI operations across process boundaries can be synchronized. /// </summary> /// <param name="app">The AppUICommand of the app to be brought to focus</param> private void FocusIsolatedApplication(IHostedAppUICommand app) { isolatedAppWithPendingUIOperation = app; System.Threading.Thread th = new Thread(new System.Threading.ThreadStart(CallSetFocus)); th.Start(); }