<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Performing Async functions in an Event Handler</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : Performing Async functions in an Event Handler</description>
  <pubDate>Wed, 10 Jun 2026 05:34:51 -700</pubDate>
  <lastBuildDate>Sat, 16 Mar 2013 05:44:46 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=4040</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Performing Async functions in an Event Handler : What I do is first do field level...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4040&amp;PID=16042#16042</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=579" rel="nofollow">gregweb</a><br /><strong>Subject:</strong> 4040<br /><strong>Posted:</strong> 16-Mar-2013 at 5:44am<br /><br />What I do is first do field level validation so that the user is notified of validation errors when he moves off the field.  Then when the user moves off the row, do row level validation.  If it fails, I just move the current row back to the former row so the user can handle the row level validation error. If the validation is fast, it appears to the user he never left the row. ]]>
   </description>
   <pubDate>Sat, 16 Mar 2013 05:44:46 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4040&amp;PID=16042#16042</guid>
  </item> 
  <item>
   <title>Performing Async functions in an Event Handler : Unless the event gives you the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4040&amp;PID=16000#16000</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 4040<br /><strong>Posted:</strong> 13-Mar-2013 at 9:22am<br /><br />Unless the event gives you the ability to signal back via the event args, you can't do this. .NET events are synchronous by nature. The UI control in this case has to support asynchronicity&nbsp;by providing callback means via the event args. If this particular event doesn't have it, than you are out of luck.<div><br></div><div>You can make an event handler async by using the async keyword, but the handler will&nbsp;immediately&nbsp;return upon the first await statement. Asynchronous methods are non-blocking methods for a very good reason. They simply pause execution whenever there is an await and resume execution once the awaited task completes, but the method itself&nbsp;immediately&nbsp;returns to the caller in order to free up the UI thread.&nbsp;</div><div><br></div><div>So, in principal this is how you would write such an event handler if the control has means to let it know when you are done.</div><div><br></div><div>public async void SomeEventHandler(object sender, SomeEventArgs args)</div><div>{</div><div>&nbsp; &nbsp; &nbsp;await SomeAsyncMethod();</div><div><br></div><div>&nbsp; &nbsp; &nbsp;args.Done(); &nbsp; // Provided there is such a thing for this event</div><div>}</div><div><br></div><div>Now having said that, you can block the UI thread while waiting for a task to complete, but you shouldn't do that. Blocking the UI defeats the whole point of asynchronous&nbsp;programming&nbsp;in the first place.&nbsp;</div><div><br></div><div>public void SomeEventHandler(object sender, SomeEventArgs args)</div><div>{</div><div>&nbsp; &nbsp; &nbsp;SomeAsyncMethod().Wait(); &nbsp; // Block thread until task completes, but really don't do this ever!!!!!</div><div>}</div>]]>
   </description>
   <pubDate>Wed, 13 Mar 2013 09:22:49 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4040&amp;PID=16000#16000</guid>
  </item> 
  <item>
   <title>Performing Async functions in an Event Handler : Hello  I am looking for advice...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4040&amp;PID=15996#15996</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=118" rel="nofollow">LowOrbit</a><br /><strong>Subject:</strong> 4040<br /><strong>Posted:</strong> 13-Mar-2013 at 8:24am<br /><br />Hello<DIV>&nbsp;</DIV><DIV>I am looking for advice on how to perform Async functions (i.e. Saving or Querying) within an event handler of a UI control. For example, I&nbsp;have a gridview and I need to perform validation and saving of a specific row before the user can move off the row. </DIV><DIV>&nbsp;</DIV><DIV>The problem is that the async calls start and execution continues with the rest of the method and exits before the async method actually completes. There may be times when a validation error occurs during the save and I want to prevent focus from leaving the row but since the grid has already allowed the user to move focus, it's too late to move it back.&nbsp;&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>A lot of event handlers have a way to signal back or return something to the sender to indicate succss or failure of an event (i.e. cancel a click event or something like that). </DIV><DIV>&nbsp;</DIV><DIV>So&nbsp;how can I perform a async call in an event handler and get the response back from the async method before exiting the handler? </DIV><DIV>&nbsp;</DIV><DIV>Thanks!</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Wed, 13 Mar 2013 08:24:06 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4040&amp;PID=15996#15996</guid>
  </item> 
 </channel>
</rss>