Skip to content

doubt to synchronize! #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rflsouza opened this issue Mar 4, 2020 · 0 comments
Open

doubt to synchronize! #21

rflsouza opened this issue Mar 4, 2020 · 0 comments

Comments

@rflsouza
Copy link

rflsouza commented Mar 4, 2020

I tried to do some ways to synchronize Callback (NavigationCompleted), but I was unsuccessful.

For example, I want to execute (ExecuteScript or PostWebMessageAsString). But I need to make sure the page loads before! I know that AddScriptToExecuteOnDocumentCreated exists and I could use it, but it's not just in the creation, in some moments if I need to run a script I have no way of knowing if the full navigation was done.

One of the examples I tested:

webviewWindow->add_NavigationCompleted(Callback<IWebView2NavigationCompletedEventHandler>(
	[&](IWebView2WebView* webview, IWebView2NavigationCompletedEventArgs * args) -> HRESULT {	
	SetEvent(NavigationCompletedEvent.Get());
	return S_OK;
}).Get(), &token);

ResetEvent(NavigationCompletedEvent.Get());

webviewWindow->Navigate(GetFullPathFor(L"htmls\\MyAppWeb.htm"));

WaitForSingleObjectEx(NavigationCompletedEvent.Get(), INFINITE, FALSE);

// Scripting Check Page HTML is READ to CLOSE!
webviewWindow->ExecuteScript(L"window.fnIsReadyToClose();", Callback<IWebView2ExecuteScriptCompletedHandler>(
	[](HRESULT errorCode, LPCWSTR resultObjectAsJson) -> HRESULT {
	LPCWSTR IsReadyToClose = resultObjectAsJson;
	//Close Window or change page etc...	
}).Get());

I tried how to run with Navigate with RunAsync (using POSTMESSAGE), but nothing!

From what I saw it is on the same thread and does not run async on another! I also didn't see anything like std :: future using a myFuture.wait (); I tried with CreateEvent and condition_variable, but it ends up the same.

I don't know if it's the best way! What do you suggest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant