|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
Hi, I have an exception when I try to destroy webview, I read a documentation and did this step: Quote:When you no longer needs the WebView, you must call the WebView's Destroy method to destroy the WebView. Destroy should be called directly, not through Send or Post method;
Code: C#
var th = new Thread(() =>
{
var threadRunner = new ThreadRunner();
var view = threadRunner.CreateWebView();
threadRunner.Send(() =>
{
//I tried view.Close(true) here, but it's wrong too
});
view.Destroy(); //Exception: Destroy must be called from the same thread the WebView is created.
threadRunner.Stop();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
Can anyone help me?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
We tested your code with the latest build and it seems to work fine. Can you check your DLL version to see if you are running the latest version? The current build is 16.0.78.0.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
Yes, I'm using latest version. I tested in small app and reproduce it, but not sure why it's happens. The problem is Create() method crashed if I didn't use ThreadRunner.Send method but in both case I not see the webView.
Code: C#
var handle = pWebView.Handle;
var th = new Thread(() =>
{
_thRunner = new ThreadRunner();
_webView = _thRunner.CreateWebView(689, 464);
_thRunner.Send(() =>
{
_webView.LoadUrlAndWait("https://www.google.ru/?gws_rd=ssl");
});
if (handle != IntPtr.Zero)
{
if(!IsService)
{
_thRunner.Send(() =>
{
_webView.Create(handle);
});
}
}
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
You will not see a WebView created by a ThreadRunner. You create a WebView in one of the two ways:
1. Calling its Create method, in which case that WebView will be associated to the thread that owns the window handle you passed to it
OR
2. Create the WebView through a ThreadRunner. In this case the WebView will not be visible;
So if you are trying to create a visible WebView, then you do not need ThreadRunner at all.
Also you do not create a ThreadRunner and a worker thread. It is not wrong but it is not necessary. ThreadRunner has an internal worker thread.
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
Ok, Thanks, I closed the issue.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
OK. Please let us know if you still have any problems.
Thanks!
|
|