async await method in C# component - Grasshopper2024-03-29T00:46:38Zhttps://www.grasshopper3d.com/forum/topics/async-await-method-in-c-component?commentId=2985220%3AComment%3A1664069&feed=yes&xn_auth=noCan you post your code? async…tag:www.grasshopper3d.com,2016-12-29:2985220:Comment:16640692016-12-29T19:27:24.522ZVicente Solerhttps://www.grasshopper3d.com/profile/VicenteSoler
<p>Can you post your code? async and await do work in scripting components. You can't use await in the RunScript method since the signature is hardcoded and you need to add the async keyword, but you can use them in your methods under <Custom additional code>.</p>
<p>See the example below (I don't think there's a clean way to avoid calling ExpireSolution to update the result).</p>
<p></p>
<p>private void RunScript(object x, object y, ref object A)<br></br> {<br></br> if(result ==…</p>
<p>Can you post your code? async and await do work in scripting components. You can't use await in the RunScript method since the signature is hardcoded and you need to add the async keyword, but you can use them in your methods under <Custom additional code>.</p>
<p>See the example below (I don't think there's a clean way to avoid calling ExpireSolution to update the result).</p>
<p></p>
<p>private void RunScript(object x, object y, ref object A)<br/> {<br/> if(result == null)<br/> {<br/> Sum(2, 2).ContinueWith(r =><br/> {<br/> result = r.Result;<br/> Component.ExpireSolution(true);<br/> });<br/> }</p>
<p> A = result;<br/> }</p>
<p> // <Custom additional code> <br/> double? result;</p>
<p> async System.Threading.Tasks.Task<double> Sum(double a, double b)<br/> {<br/> await System.Threading.Tasks.Task.Delay(5000);<br/> return a + b;<br/> }<br/> // </Custom additional code></p>
<p><code> </code></p>