Stop asynchronous execution after exception in browser proce

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Stop asynchronous execution after exception in browser proce

Postby wierdfantasy » Thu Apr 10, 2014 11:30 am

Hi,

We have a scenario wherein in multi process mode, if any error occurs in Browser process message processing, we want to throw an exception and stop any further processing of asynchronous operations.

Currently we are catching the exception in OnProcessMessageReceived of Browser process and then send back a message to Render process to execute error callback written in Javascript.

But due to asynchronous nature of execution, process messages keep on coming to Browser process for processing.

Thoughts?

Thanks,
Shitiz
wierdfantasy
Techie
 
Posts: 20
Joined: Thu Apr 10, 2014 11:22 am

Re: Stop asynchronous execution after exception in browser p

Postby wierdfantasy » Mon Apr 14, 2014 7:06 am

Any thoughts guys?
wierdfantasy
Techie
 
Posts: 20
Joined: Thu Apr 10, 2014 11:22 am

Re: Stop asynchronous execution after exception in browser p

Postby magreenblatt » Mon Apr 14, 2014 8:31 am

It depends on what your application does, and what an error means. Can you provide examples?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Stop asynchronous execution after exception in browser p

Postby wierdfantasy » Tue Apr 15, 2014 6:39 am

Its just about showing up a simple Error MessageBox if any error occurs in OnProcessMessageReceived of browser process and then probably exiting the application altogether.

What i currently did was to not throw an exception but instead whenever an exception occurs, switch to UI thread of browser process and then Show an Error message and then close the form having the embedded browser control.

Problem with this is that everything occurs asynchronously.
So by the time message is displayed and form closed, other message have already arrived from Render process, which then throw ObjectDisposed exception when accessing the disposed off from.

This is the code snippet responsible for handling processing of message for getting appropriate data to display on Browser control:-

else if (message.Name == "bp_getWidgetDataAsJson")
{
string strDshWidgetKey = message.Arguments.GetInt(0).ToString();
decimal dashWidgetKey = Decimal.Parse(strDshWidgetKey);
string strWidgetPlaceHolderId = message.Arguments.GetString(1);

if (dashboardControl!=null && dashboardControl.InvokeRequired)
{
GetWidgetDataAsJsonHandler getWidgetDataAsJsonHandler = GetWidgetDataAsJson;
IAsyncResult result = dashboardControl.BeginInvoke(getWidgetDataAsJsonHandler, dashboardControl, dashWidgetKey);
object objresult = dashboardControl.EndInvoke(result);
if (((IDashboardController)dashboardControl.Controller).Exception != null)
{
if (dashboardControl.InvokeRequired)
{
GenerateErrorAndCloseDashboardControl(dashboardControl);
}
}
else
{
string widgetDataAsJson = null;
if (objresult != null)
widgetDataAsJson = objresult.ToString();
CefProcessMessage retmessage = CefProcessMessage.Create("rp_getWidgetDataAsJsonCallback");
retmessage.Arguments.SetString(0, widgetDataAsJson);
retmessage.Arguments.SetString(1, strWidgetPlaceHolderId);
retmessage.Arguments.SetString(2, strDshWidgetKey);
browser.SendProcessMessage(CefProcessId.Renderer, retmessage);
}
}
}

So by the time control is inside GenerateErrorAndCloseDashboardControl for displaying message and closing the form, other bp_getWidgetDataAsJson messages have already arrived.
wierdfantasy
Techie
 
Posts: 20
Joined: Thu Apr 10, 2014 11:22 am

Re: Stop asynchronous execution after exception in browser p

Postby magreenblatt » Tue Apr 15, 2014 9:24 am

You could associate some unique token with the form. Once you have an error for that form discard any additional messages that share the same token. Do that all on the same thread (marking the token as invalid and discarding the messages) so you don't introduce a race condition.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 10 guests