Я много раз читал, что если await встречает Таск, который ещё не выполнен, то метод возвращает незавершённый таск и выполнение продолжается в вызывающем методе.
static async Task Method1Async()
{
Console.WriteLine("Starting Method1Async Thread id: "+ Thread.CurrentThread.ManagedThreadId);
var task = Method2Async();
await task; // До этой точки код выполняется синхронно (если таска ещё не готова)
Console.WriteLine("End Method1Async Thread id: " + Thread.CurrentThread.ManagedThreadId);
}
static async Task Method2Async()
{
Thread.Sleep(100); // Thread.Sleep - это блокирующая операция
Console.WriteLine("Starting Method2Async Thread id: "+ Thread.CurrentThread.ManagedThreadId);
await Task.Yield(); // До этой точки код выполняетя синхронно. Task.Yield освобождает поток всегда
Console.WriteLine("End Method2Async Thread id: " + Thread.CurrentThread.ManagedThreadId);
}
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Hotel {
public int id { get; set; }
public int countryId { get; set; }
public string country { get; set; }
public string countryUrl { get; set; }
public int regionId { get; set; }
public string region { get; set; }
public string regionUrl { get; set; }
public string hotelType { get; set; }
public string name { get; set; }
public string comment { get; set; }
public string imageFolder { get; set; }
public string imageHotel { get; set; }
public string minPrice { get; set; }
public bool showHalfPrice { get; set; }
public string minPriceCurrency { get; set; }
public List<object> restTypes { get; set; }
public bool tour3D { get; set; }
public string video { get; set; }
public bool tezRecommend { get; set; }
public bool tezPriority { get; set; }
public bool tezOnly { get; set; }
public string price { get; set; }
}
public class Root {
public Hotel[] hotels { get; set; }
}
var data = JsonConvert.DeserializeObject<Root>(jsonText);
var names = data.hotels.Select(x=>x.name).ToArray();
я не совсем опытен для таких начинаний