by 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.