c# - Async methods not running -


i'm trying hang of async-await methods i'm not getting hang of it. used webrequest, simple sadly synchronous.

my problem starttest() not running -- "because call not awaited, execution of current method continues before call completed. consider applying 'await' operator result of call'. can't add await before parent method main, , can't of course async method. realize understanding of async horrible -- point me in right way?

static void main(string[] args)     {         starttest();          async task<string> starttest()         {             using (var client = new httpclient())             {                 list<string> urls = new list<string> { //a list of urls want check };                  if (await getstatuscodes(urls) != true)                 {                     return "not ok";                 }             }              return "ok";          }           async task<bool> getstatuscodes(ilist<string> urls)         {             using (var client = new httpclient())             {                 foreach (var url in urls)                 {                     var response = await client.getasync(url);                     if (response.statuscode.tostring() != "ok")                     {                         return false;                     }                 }                  return true;             }         }     } 

you can make mainasync method put stuff in want run async.

e.g.

private static void main() {     mainasync().wait(); } private static async task mainasync() {     // async stuff } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -