This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19178|Reply: 0

[Source] The current thread is not in a single-threaded unit, so the ActiveX control "8856f961-340a-11d0-a96" cannot be instantiated

[Copy link]
Posted on 10/11/2015 10:32:39 PM | | |
This article mainly introduces the content of "The current thread is not in a single-threaded unit, so the ActiveX control cannot be instantiated" "8856f961-340a-11d0-a96"", which mainly involves the content of the ActiveX control "8856f961-340a-11d0-a96" that cannot be instantiated because the current thread is not in a single-threaded unit. 8856f961-340a-11d0-a96", interested students can refer to it.

  1. private static string htmlstr;
  2.         private static void GetHtmlWithBrowser(object url)
  3.         {
  4.             htmlstr = string.Empty;

  5.             WebBrowser wb = new WebBrowser();
  6.             wb.AllowNavigation = true;
  7.             wb.Url = new Uri(url.ToString());
  8.             DateTime dtime = DateTime.Now;
  9.             double timespan = 0;
  10.             while (timespan < 10 || wb.ReadyState != WebBrowserReadyState.Complete)
  11.             {
  12.                 Application.DoEvents();
  13.                 DateTime time2 = DateTime.Now;
  14.                 timespan = (time2 - dtime).TotalSeconds;
  15.             }

  16.             if (wb.ReadyState == WebBrowserReadyState.Complete)
  17.             {
  18.                 htmlstr = wb.DocumentText;
  19.             }
  20.         }

  21.         /// <summary>
  22.         /// 在单线程中启用浏览器
  23.         /// </summary>
  24.         public static void RunWithSingleThread(object url, ref string html)
  25.         {
  26.             ParameterizedThreadStart ps = new ParameterizedThreadStart(GetHtmlWithBrowser);
  27.             Thread t = new Thread(ps);
  28.             t.IsBackground = true;
  29.             t.ApartmentState = ApartmentState.STA;
  30.             t.Start(url);
  31.             html = htmlstr;
  32.         }
Copy code






Previous:WinForm develops the browser, and WebBrowser obtains the page content and solves Chinese garbled characters
Next:The computer is detected and cannot access the Internet with multiple IPs? Use Ruijie Assistant to solve it
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com