protected override void Execute(NativeActivityContext context) { try { Browser getBrowser = currBrowser.Get(context); if (getBrowser != null) { if (getBrowser.getICFBrowser() != null) { if (UiBrowser != null) { UiBrowser.Set(context, getBrowser); } } context.ScheduleAction(Body, getBrowser, OnCompleted, OnFaulted); } } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "附加浏览器出现异常", e.Message); if (!ContinueOnError.Get(context)) { throw; } } }
protected override void Execute(NativeActivityContext context) { try { Int32 _timeout = TimeoutMS.Get(context); Thread.Sleep(_timeout); latch = new CountdownEvent(1); Thread td = new Thread(() => { if (Selector.Expression == null) { Browser getBrowser = currBrowser.Get(context); if (getBrowser != null) { if (getBrowser.getIEBrowser() != null) { if (UiBrowser != null) { UiBrowser.Set(context, getBrowser); } } context.ScheduleAction(Body, getBrowser, OnCompleted, OnFaulted); } } else { var allBrowsers = new SHDocVw.ShellWindows(); switch (BrowserType) { case BrowserTypes.IE: { var selStr = Selector.Get(context); UiElement element = UiElement.FromSelector(selStr); IntPtr handle = IntPtr.Zero; if (element != null) { handle = element.WindowHandle; } mshtml.IHTMLDocument2 currDoc = null; SHDocVw.InternetExplorer ieBrowser = GetIEFromHWndClass.GetIEFromHWnd((int)handle, out currDoc); Browser thisBrowser = new Browser(); thisBrowser.SetIEBrowser(ieBrowser); if (UiBrowser != null) { UiBrowser.Set(context, thisBrowser); } ArrayList list = new ArrayList(); var allShellWindows = new SHDocVw.ShellWindows(); foreach (SHDocVw.InternetExplorer browser in allShellWindows) { list.Add(browser); } CommonVariable.BrowsersList = list; context.ScheduleAction(Body, thisBrowser); break; } case BrowserTypes.Chrome: { break; } case BrowserTypes.Firefox: { break; } default: break; } } refreshData(latch); }); td.TrySetApartmentState(ApartmentState.STA); td.IsBackground = true; td.Start(); latch.Wait(); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "出现异常", e.Message); if (ContinueOnError.Get(context)) { } } }