async-await

How to use Task.WhenAny and implement retry

北城余情 提交于 2020-04-07 05:01:09
问题 I have a solution that creates multiple I/O based tasks and I'm using Task.WhenAny() to manage these tasks. But often many of the tasks will fail due to network issue or request throttling etc. I can't seem to find a solution that enables me to successfully retry failed tasks when using a Task.WhenAny() approach. Here is what I'm doing: var tasks = new List<Task<MyType>>(); foreach(var item in someCollection) { task.Add(GetSomethingAsync()); } while (tasks.Count > 0) { var child = await Task

How to use Task.WhenAny and implement retry

こ雲淡風輕ζ 提交于 2020-04-07 05:01:07
问题 I have a solution that creates multiple I/O based tasks and I'm using Task.WhenAny() to manage these tasks. But often many of the tasks will fail due to network issue or request throttling etc. I can't seem to find a solution that enables me to successfully retry failed tasks when using a Task.WhenAny() approach. Here is what I'm doing: var tasks = new List<Task<MyType>>(); foreach(var item in someCollection) { task.Add(GetSomethingAsync()); } while (tasks.Count > 0) { var child = await Task

Converting EF Core queries from 2.2 to 3.0 - async await

女生的网名这么多〃 提交于 2020-04-07 04:01:04
问题 In EF Core 2.2 I had: var data = await _ArticleTranslationRepository.DbSet .Include(arttrans => arttrans.Article) .ThenInclude(art => art.Category) .Where(trans => trans.Article != null && trans.Article.Category != null && trans.Article.Category.Id == categoryId.Value) .GroupBy(trans => trans.ArticleId) .Select(g => new { ArticleId = g.Key, TransInPreferredLang = g.OrderByDescending(trans => trans.LanguageId == lang).ThenByDescending(trans => trans.LanguageId == defaultSiteLanguage).ThenBy

Converting EF Core queries from 2.2 to 3.0 - async await

坚强是说给别人听的谎言 提交于 2020-04-07 03:58:16
问题 In EF Core 2.2 I had: var data = await _ArticleTranslationRepository.DbSet .Include(arttrans => arttrans.Article) .ThenInclude(art => art.Category) .Where(trans => trans.Article != null && trans.Article.Category != null && trans.Article.Category.Id == categoryId.Value) .GroupBy(trans => trans.ArticleId) .Select(g => new { ArticleId = g.Key, TransInPreferredLang = g.OrderByDescending(trans => trans.LanguageId == lang).ThenByDescending(trans => trans.LanguageId == defaultSiteLanguage).ThenBy

async await with setInterval

﹥>﹥吖頭↗ 提交于 2020-04-06 04:51:10
问题 function first(){ console.log('first') } function second(){ console.log('second') } let interval = async ()=>{ await setInterval(first,2000) await setInterval(second,2000) } interval(); Imagine that I have this code above. When I run it, first() and second() will be called at the same time; how do I call second() after first)() returns some data, for example, if first() is done, only then call second() ? Because first() in my code will be working with a big amount of data and if this 2

Using Combine's Future to replicate async await in Swift

若如初见. 提交于 2020-03-25 18:47:11
问题 I am creating a Contact Class to fetch user's phoneNumbers asynchronously. I created 3 functions that leveraged on the new Combine framework's Future. func checkContactsAccess() -> Future<Bool, Never> { Future { resolve in let authorizationStatus = CNContactStore.authorizationStatus(for: .contacts) switch authorizationStatus { case .authorized: return resolve(.success(true)) default: return resolve(.success(false)) } } } func requestAccess() -> Future<Bool, Error> { Future { resolve in

“A second operation started on this context” EF core 3.1 concurrency breaking change [duplicate]

廉价感情. 提交于 2020-03-25 16:20:13
问题 This question already has answers here : Entity Framework Core thread safe? (1 answer) Is DbContext thread safe? (3 answers) Entity Framework Thread Safety (3 answers) Closed 18 days ago . I'm migrating from netcoreapp 2.1 to 3.1, and I've found a breaking change for EF core 3.1 that I can't resolve. Previously in 2.1, this worked: taskList.Add(MethodOne(myRequestObject)); taskList.Add(MethodTwo(myRequestObject)); await Task.WhenAll(taskList); where both methods only read(never changed) from

“A second operation started on this context” EF core 3.1 concurrency breaking change [duplicate]

这一生的挚爱 提交于 2020-03-25 16:17:23
问题 This question already has answers here : Entity Framework Core thread safe? (1 answer) Is DbContext thread safe? (3 answers) Entity Framework Thread Safety (3 answers) Closed 18 days ago . I'm migrating from netcoreapp 2.1 to 3.1, and I've found a breaking change for EF core 3.1 that I can't resolve. Previously in 2.1, this worked: taskList.Add(MethodOne(myRequestObject)); taskList.Add(MethodTwo(myRequestObject)); await Task.WhenAll(taskList); where both methods only read(never changed) from

Xamarin - Bind ActivityIndicator visibility to async Task finished

大憨熊 提交于 2020-03-25 16:08:33
问题 I'm loading images async into my Listview according to this answer: Xamarin - Asynchronous data binding I'd like to display a ActivityIndicator while the page is loading the data from the web, but cannot figure out how to bind the visibility it to the task, so that it disappears when the task is done loading.. I've created a isLoading bool variable in my ViewModel. I tried it this way in my ViewModel, but It's not working: isLoading = true; GetImagesCommand = new Command(async () => await

Xamarin - Asynchronous data binding

瘦欲@ 提交于 2020-03-25 13:43:55
问题 I have following code: Page with lots of images, that are loaded dynamically with the databinding: base.OnAppearing(); if (!loaded) { loaded = true; BindingContext = new GalleryViewModel(pCode, gCode, gUrl); } viewmodel: namespace GalShare.ViewModel { class GalleryViewModel { public string pCode { get; set; } public string gCode { get; set; } public string gUrl { get; set; } public ObservableCollection<picdata> Galleries { get; set; } public GalleryViewModel(string pCode, string gCode, string