Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>There a few things to take care about "async" are as follows :</strong></p> <ul> <li>The method should only be "async" when it <strong>needs to wait</strong> for the <strong>action to be performed</strong> by the code written in that.</li> <li>if there is nothing to be "await" in the method, than that method should not declared as "async".</li> <li>if there is any event (or else event handler) to be marked as async then return type should be "void" or any specific return type</li> <li>but if any other (general) method should marked as "async" then the return type should be <code>Task</code> or <code>Task&lt; return-type &gt;</code> .</li> </ul> <p><strong>Now coming to your questions,</strong></p> <ul> <li>definitely you can mark "Controller", "Event" &amp; "Page" as async (I'm not damn sure about marking the page as async coz i never used it) and by that those method will take rest until the action will be performed completely written in that method.</li> <li>And that's the actual system to encapsulate whole the initialization logic in a viewModel. <ul> <li>for that make a Floder, named it as "ViewModels" and put all of the viewModel Codes in that folder and whenever needed, use that.</li> </ul></li> </ul> <p>You should put your this code in a ViewModel:</p> <pre><code>private async void SetData(TestDataWebServiceHelper service) { listA = await this.SetListA(service); listB = await this.SetListB(service); } private async Task&lt;IEnumerable&lt;SelectListItem&gt;&gt; SetListA(TestDataWebServiceHelper service) { List&lt;String&gt; rawList = new List&lt;String&gt;(); rawList = await service.GetValuesAsync("json"); return rawList.Select(x =&gt; new SelectListItem { Text = x, Value = x }); } private async Task&lt;IEnumerable&lt;SelectListItem&gt;&gt; SetListB(TestDataWebServiceHelper service) { List&lt;String&gt; rawList = new List&lt;String&gt;(); rawList = await service.GetValuesAsync("json"); return rawList.Select(x =&gt; new SelectListItem { Text = x, Value = x }); } </code></pre> <p>and then you should call it whenever needed.</p> <p><strong>(Hope this helps...)</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload