<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Silverlight Page Lifecycle Problems with Asyncronous Event Handler in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/silverlight-page-lifecycle-problems-with/m-p/16403#M1503</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c#" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; QueryTask queryTask = new QueryTask(myLayer.Url + "/" + layerID); &amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.ExecuteCompleted += new EventHandler&amp;lt;QueryEventArgs&amp;gt;(queryCountyTask_ExecuteCompleted); &amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.ExecuteAsync(query);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is also a bit of code which calls a JavaScript function on-page to hide a Panel.&amp;nbsp; The inclusion of this code causes a full page postback.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c#" name="code"&gt;HtmlPage.Window.Invoke("hideReport");&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is that sometimes the &lt;EM&gt;queryCountyTask_ExecuteCompleted()&lt;/EM&gt; Silvelright event fires before the &lt;EM&gt;Page_Init()&lt;/EM&gt; Page event and sometimes it fires after.&amp;nbsp; 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.&amp;nbsp; As long as the Silverlight event fires after the Page event, the Session variables are still present and everything works fine.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to order the events so as to avoid these race conditions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Apr 2015 14:45:46 GMT</pubDate>
    <dc:creator>BradleyPerniciaro</dc:creator>
    <dc:date>2015-04-14T14:45:46Z</dc:date>
    <item>
      <title>Silverlight Page Lifecycle Problems with Asyncronous Event Handler</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/silverlight-page-lifecycle-problems-with/m-p/16403#M1503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c#" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; QueryTask queryTask = new QueryTask(myLayer.Url + "/" + layerID); &amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.ExecuteCompleted += new EventHandler&amp;lt;QueryEventArgs&amp;gt;(queryCountyTask_ExecuteCompleted); &amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.ExecuteAsync(query);&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is also a bit of code which calls a JavaScript function on-page to hide a Panel.&amp;nbsp; The inclusion of this code causes a full page postback.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c#" name="code"&gt;HtmlPage.Window.Invoke("hideReport");&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is that sometimes the &lt;EM&gt;queryCountyTask_ExecuteCompleted()&lt;/EM&gt; Silvelright event fires before the &lt;EM&gt;Page_Init()&lt;/EM&gt; Page event and sometimes it fires after.&amp;nbsp; 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.&amp;nbsp; As long as the Silverlight event fires after the Page event, the Session variables are still present and everything works fine.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to order the events so as to avoid these race conditions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2015 14:45:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/silverlight-page-lifecycle-problems-with/m-p/16403#M1503</guid>
      <dc:creator>BradleyPerniciaro</dc:creator>
      <dc:date>2015-04-14T14:45:46Z</dc:date>
    </item>
  </channel>
</rss>

