<?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 : Wrapping background worker with OperationResult</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : Wrapping background worker with OperationResult</description>
  <pubDate>Mon, 13 Apr 2026 19:53:02 -700</pubDate>
  <lastBuildDate>Thu, 26 Jul 2012 10:52:28 -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=3553</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>Wrapping background worker with OperationResult : Actually I just realized you don&amp;#039;t...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3553&amp;PID=14089#14089</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> 3553<br /><strong>Posted:</strong> 26-Jul-2012 at 10:52am<br /><br />Actually I just realized you don't need .AsOperationResult after .OnComplete. OnComplete already returns an OperationResult or OperationResult&lt;T&gt;.]]>
   </description>
   <pubDate>Thu, 26 Jul 2012 10:52:28 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3553&amp;PID=14089#14089</guid>
  </item> 
  <item>
   <title>Wrapping background worker with OperationResult : Glad you are doing things asynchronously...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3553&amp;PID=14088#14088</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> 3553<br /><strong>Posted:</strong> 26-Jul-2012 at 10:47am<br /><br />Glad you are doing things asynchronously in WPF. That's how it should be done, even though you have the option of doing it synchronously. <DIV>&nbsp;</DIV><DIV>Yes, there is a way to do this. The "Cocktail Async Pack for VS 2012" defines AsOperationResult for Task and Task&lt;T&gt;. Assuming that you are not doing this in VS 2012 just yet, you can grab TaskFns.cs from Github and drop it into your project. Once there you can do the following:</DIV><DIV>&nbsp;</DIV><DIV><SPAN style="COLOR: blue">yield</SPAN>&nbsp;<SPAN style="COLOR: blue">return</SPAN>&nbsp;Task.Factory.StartNew(() =&gt; DoSomethingSynchronous()).AsOperationResult();<BR></DIV><DIV>The same file also defines overloads for Task.OnComplete() and Task&lt;T&gt;.OnComplete() to do the onSuccess, onFail callbacks. So your StartService method would look something like this:</DIV><DIV>&nbsp;</DIV><DIV>public OperationResult StartService(string serviceName, Action onSuccess, Action&lt;Exception&gt; onFail)</DIV><DIV>{</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Task.Factory.StartNew(() =&gt; DoStartService(serviceName))</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.OnComplete(onSuccess, onFail);</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <STRIKE>.AsOperationResult();</STRIKE></DIV><DIV>}</DIV><DIV>&nbsp;</DIV><DIV>You can even return a value at the end from your task back the the UI thread. For example if you want to return true or false to indicate whether the service started or not, you can do that like this:</DIV><DIV>&nbsp;</DIV><DIV>public bool DoStartService(string serviceName)</DIV><DIV>{</DIV><DIV>&nbsp;&nbsp;&nbsp; ......</DIV><DIV>&nbsp;&nbsp;&nbsp; return resultValue;</DIV><DIV>}</DIV><DIV>&nbsp;</DIV><DIV><DIV>public OperationResult&lt;bool&gt; StartService(string serviceName, Action&lt;bool&gt; onSuccess, Action&lt;Exception&gt; onFail)</DIV><DIV>{</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Task.Factory.StartNew(() =&gt; DoStartService(serviceName))&nbsp;&nbsp; // This will now return Task&lt;bool&gt;</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.OnComplete(onSuccess, onFail);</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <STRIKE>.AsOperationResult();</STRIKE></DIV><DIV>}</DIV></DIV><span style="font-size:10px"><br /><br />Edited by mgood - 26-Jul-2012 at 10:54am</span>]]>
   </description>
   <pubDate>Thu, 26 Jul 2012 10:47:52 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3553&amp;PID=14088#14088</guid>
  </item> 
  <item>
   <title>Wrapping background worker with OperationResult : I am writing a WPF application...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3553&amp;PID=14087#14087</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1009" rel="nofollow">JohnBloom</a><br /><strong>Subject:</strong> 3553<br /><strong>Posted:</strong> 26-Jul-2012 at 7:36am<br /><br />I am writing a WPF application to manage our server side processes. Some of those processes involve long running tasks like starting and stopping windows services and interacting with windows in general. Since I come from a silverlight background I am still making everything asynchronous.&nbsp;<div><br></div><div>I was wondering if there was a way to wrap code that is synchronous in OperationResult so I can chain it in a coroutine. I know that a coroutine can do both synchronous and asynchronous but it is still running the synchronous task on the ui thread. I need some way to push it onto another thread but I would still like to call it like it is an async domain call.</div><div><br></div><div><pre style="font-family: C&#111;nsolas; font-size: 13px; : white; -: initial initial; -repeat: initial initial; "><span style="color:blue;">yield</span>&nbsp;<span style="color:blue;">return</span>&nbsp;_ServiceCenterUnitOfWork.WindowsServiceDomain.StartService(serviceName, null, ShowError);</pre><pre style="font-family: C&#111;nsolas; font-size: 13px; : white; -: initial initial; -repeat: initial initial; "><br></pre><pre style="font-family: C&#111;nsolas; font-size: 13px; : white; -: initial initial; -repeat: initial initial; "><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; line-height: 14.545454025268555px; white-space: normal; ">&nbsp;Something like that.</span></pre><pre style=": white; "><font face="Verdana, Arial, Helvetica, sans-serif"><span style="white-space: normal;">-John</span></font></pre></div>]]>
   </description>
   <pubDate>Thu, 26 Jul 2012 07:36:53 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3553&amp;PID=14087#14087</guid>
  </item> 
 </channel>
</rss>