In my ASP.net web application, I have code in the Page_Init event() of my Page which checks some session variables to redirect users if a Session timeout has occurred.
In my Silverlight application I have a button event handler which executes some ESRI ArcGIS code asynchronously, and which configures an event handler which fires when the asynchronous call completes:
QueryTask queryTask = new QueryTask(myLayer.Url + "/" + layerID);
queryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(queryCountyTask_ExecuteCompleted);
queryTask.ExecuteAsync(query);
There is also a bit of code which calls a JavaScript function on-page to hide a Panel. The inclusion of this code causes a full page postback.
HtmlPage.Window.Invoke("hideReport");
My problem is that sometimes the queryCountyTask_ExecuteCompleted() Silvelright event fires before the Page_Init() Page event and sometimes it fires after. In those cases where the Silverlight fires before the Page event, the Session state is empty, causing the user to be incorrectly redirect to a "your session has timed-out" page. As long as the Silverlight event fires after the Page event, the Session variables are still present and everything works fine.
It looks like the placement of the Invoke method has no bearing on when the Page-level event is fired, so the order of events appears to be seemingly random. Is there a way to order the events so as to avoid these race conditions?
Is there a way to coordinate these asychronous callback events with the normal Page Lifecycle of a web application page so as to avoid these race conditions?
If you flip the problem around how about getting your ASP.net page to fire the Silverlight functions after it has completed so there will be no race condition.
Here is a Link on how to make events in Silverlight scriptable from external javascript that should help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With