|
Rank: Member Groups: Member
Joined: 2/18/2020 Posts: 24
|
Hi, I get: "Either the ThreadRunner object must be explicitly destroyed or all WebViews associated to the ThreadRunner must have been destroyed before exiting the application or shutting down the AppDomain" Stack trace: EO.Base.Runtime.sqkq(Object kkt, Exception kku, Boolean kkv) EO.Base.ThreadRunnerBase.OnException(Exception ex, Boolean exiting) EO.Base.ThreadRunnerBase.bwrm(Boolean knf) EO.Base.ThreadRunnerBase.bwrm() EO.Internal.dnvo.bwrm() System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) System.Threading.ThreadHelper.ThreadStart() However, my code disposes everything (as far as I understand):
Code: C#
var threadRunner = new ThreadRunner();
var webView = threadRunner.CreateWebView();
try
{
webView.CertificateError += (s, e) => { e.Continue(); };
webView.Resize(1920, 1000);
threadRunner.Send(() =>
{
try
{
try
{
foreach (var item in myCookies.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
{
try
{
var nameAndValue = item.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
if (nameAndValue.Length > 1)
{
webView.Engine.CookieManager.SetCookie(new EO_WebEngine.Cookie(nameAndValue[0], nameAndValue[1]));
}
}
catch { }
}
}
catch { }
var navigation = webView.LoadUrl(myUrl);
navigation.WaitOne(10 * 1000);
if (navigation.HttpStatusCode == 200)
{
Thread.Sleep(3000);
var html = webView.EvalScript("document.documentElement.outerHTML", false).ToString();
if (!string.IsNullOrWhiteSpace(html))
{
var url = webView.EvalScript("document.location.href", false).ToString();
if (!string.IsNullOrWhiteSpace(url))
{
// some logic using the page's HTML and URL...
}
}
}
try
{
webView.Dispose();
}
catch { }
}
catch { }
try
{
threadRunner.Dispose();
}
catch { }
try
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch { }
finally
{
Environment.Exit(0);
}
});
}
catch { }
finally
{
try
{
webView.Dispose();
}
catch { }
try
{
threadRunner.Dispose();
}
catch { }
}
Please advise what we need to fix. Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, You should not try to dispose the WebView or the ThreadRunner inside the ThreadRunner.Send method. You only need to destroy the WebView afterwards. So the code should be something like this:
Code: C#
var threadRunner = new ThreadRunner();
var webView = threadRunner.CreateWebView();
threadRunner.Send(() =>
{
....do something with the WebView
});
webView.Destroy();
threadRunner.Stop();
Please let us know if this works for you. Thanks!
|
|
Rank: Member Groups: Member
Joined: 2/18/2020 Posts: 24
|
The threadRunner.Send will block the thread?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Yes. That's the whole purpose of Send. If you do not want it to block, you use Post.
|
|
Rank: Member Groups: Member
Joined: 2/18/2020 Posts: 24
|
Thank you, however, we still get the error. The updated code:
Code: C#
var threadRunner = new ThreadRunner();
var webView = threadRunner.CreateWebView();
try
{
webView.CertificateError += (s, e) => { e.Continue(); };
webView.Resize(1920, 1000);
threadRunner.Send(() =>
{
try
{
try
{
foreach (var item in myCookies.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
{
try
{
var nameAndValue = item.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
if (nameAndValue.Length > 1)
{
webView.Engine.CookieManager.SetCookie(new EO_WebEngine.Cookie(nameAndValue[0], nameAndValue[1]));
}
}
catch { }
}
}
catch { }
var navigation = webView.LoadUrl(myUrl);
navigation.WaitOne(10 * 1000);
if (navigation.HttpStatusCode == 200)
{
Thread.Sleep(3000);
var html = webView.EvalScript("document.documentElement.outerHTML", false).ToString();
if (!string.IsNullOrWhiteSpace(html))
{
var url = webView.EvalScript("document.location.href", false).ToString();
if (!string.IsNullOrWhiteSpace(url))
{
// some logic
}
}
}
}
catch { }
});
}
catch { }
finally
{
try
{
webView.Destroy();
webView.Dispose();
}
catch { }
try
{
threadRunner.Stop();
threadRunner.Dispose();
}
catch { }
}
try
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch { }
finally
{
Environment.Exit(0);
}
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
We tested your code here (without the cookie part) on the latest version and it works fine. Which version of our DLLs are you using?
|
|
Rank: Member Groups: Member
Joined: 2/18/2020 Posts: 24
|
I don't think it is consistent. It happens on the production server "from time to time". I'm using v20.2.34.0.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, I am not sure what else to tell you then. If you continue to have problem, you can try to isolate the problem into a test project and send the test to us. See here for more details: https://www.essentialobjects.com/forum/test_project.aspxOnce we have the test project, we will investigate further. Thanks
|
|
Rank: Member Groups: Member
Joined: 2/18/2020 Posts: 24
|
Since it happens from time to time I don't have a way to reproduce it. I thought that this is related to the fact that I'm using environment.exit
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
We will need a test project to investigate further. You can send the test project to us even if it only occurs from time to time. For example, if it happens once after you run the test project 10 times, then it will still be very useful because we can still use it to reproduce the problem.
Thanks
|
|