async-await

does not contain a definition for 'GetAwaiter'

筅森魡賤 提交于 2019-12-23 10:07:43
问题 Im getting the below error with the below set of code, It is erroring on the 'alliancelookup' line, I'm not sure what i'm doing wrong but I couldn't see anything myself. The query im running to crest seems to be running fine but It seems the issue im having is with the Awaiter, I was wondering if there was a way around this? DynamicCrest crest = new DynamicCrest(); var root = await crest.GetAsync(crest.Host); var alliancelookup = await (await root.GetAsync(r => r.alliances)).First(i => i

Async/Await or Task.Run in Console Application/Windows Service

我们两清 提交于 2019-12-23 09:57:40
问题 I have been researching (including looking at all other SO posts on this topic) the best way to implement a (most likely) Windows Service worker that will pull items of work from a database and process them in parallel asynchronously in a 'fire-and-forget' manner in the background (the work item management will all be handled in the asynchronous method). The work items will be web service calls and database queries. There will be some throttling applied to the producer of these work items to

Why is the culture kept after ConfigureAwait(false)

久未见 提交于 2019-12-23 09:34:07
问题 I have the following async code: // Main system culture is English here Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("es"); WriteLine($"{Thread.CurrentThread.ManagedThreadId}:Culture:{Thread.CurrentThread.CurrentCulture}"); await Task.Delay(1).ConfigureAwait(false); WriteLine($"{Thread.CurrentThread.ManagedThreadId}:Culture:{Thread.CurrentThread.CurrentCulture}"); The resul I expected would be to have a different thread id after the await and that new thread id having the

Is there a callback for when a task is completed in Task.WhenAll

大城市里の小女人 提交于 2019-12-23 09:01:46
问题 Suppose I have the following: IEnumerable<Task<TimeSpan>> tasks = //... TimeSpan[] results = await Task.WhenAll(tasks); // Handle results By the time I can handle the results all the task must have finished. Is there a way to handle each result on demand ? Like registering a delegate / callback that will get executed when a task is completed: IEnumerable<Task<TimeSpan>> tasks = //... await Task.WhenAll(tasks, result => { // A task has finished. This will get executed. // result is of type

perl6 IO::Socket::Async server dies with the exception: connection reset by peer

痞子三分冷 提交于 2019-12-23 08:47:54
问题 Here is the echo server code: #!/usr/bin/env perl6 my $port = 3333 ; say "listen port $port" ; react { my $ids = 0 ; whenever IO::Socket::Async.listen('0.0.0.0', $port ) -> $conn { my $id = $ids++ ; $conn.print( "$id: hello\n") ; whenever $conn.Supply.lines -> $line { say "$id: $line" ; $conn.print( "$id : $line\n") ; } } } here is the client code: #!/usr/bin/env perl6 my $port = 3333 ; my $conn = await IO::Socket::Async.connect('localhost', $port ); $conn.print: "{time}\n"; #$conn.Supply.tap

How does the new async/await feature in C# 5 integrate with the message loop?

邮差的信 提交于 2019-12-23 07:57:14
问题 I've not had chance to check out the CTP of the new C# async/await feature, but here's something I was wondering: How does it integrate with the message loop? I assume that in a standard Windows application (Winforms, WPF) the continuations are called by sending messages to the application's message loop, using a Dispatcher or similar? What if I'm not using a standard windows message loop? For example in a GTK# application or in a console application (if indeed this feature could be of use at

This async method lacks 'await' operators and will run synchronously

本小妞迷上赌 提交于 2019-12-23 07:42:44
问题 my program has 3 warnings of the following statement: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. What is the warning try to tell me? What should I do? This is my code: Is it running using multi-threading? static void Main(string[] args) { Task task1 = new Task(Work1); Task task2 = new Task(Work2); Task task3 = new Task(Work3);

Why is there no SingleOrDefaultAsync for IQueryables?

别来无恙 提交于 2019-12-23 07:38:10
问题 The following code does not compile because SingleOrDefaultAsync() is not a suitable extension for GetAppointments(). I was just wondering why ... public IQueryable<Appointment> GetAppointments() { return Context.Appointments; } public async Task<Appointment> GetAppointmentAsync(int appointmentId) { return await GetAppointments().SingleOrDefaultAsync(a => a.ID == appointmentId); } I am using EF 6.0.0. And please ignore what I am doing here exactly. I just tried to make things easier than they

Babel - regeneratorRuntime is not defined, when using transform-async-to-generator plugin

雨燕双飞 提交于 2019-12-23 07:29:44
问题 I am not able to setup babel correctly for the usage of async / await. I am using babel 7 and webpack 4. I do not want to use babel-polyfill if possible! My babelrc file: { "presets": [[ "@babel/env", {"modules": false} ]], "plugins": [ "syntax-dynamic-import", "transform-async-to-generator" ] } Code: async function init() { const loaderData = await initLoader(); initCmp(loaderData) .then(initApi(loaderData.key)) .catch(); } init(); And Error: refactor.main.js:18 Uncaught ReferenceError:

Check calls Received() for async method

旧时模样 提交于 2019-12-23 07:19:07
问题 When I run the following code: [Test] public async Task Can_Test_Update() { var response = await _controller.UpdateAsync(Guid.NewGuid()); response.Valid.Should().BeTrue(); _commands.Received().UpdateAsync( Arg.Is<Something>( l => l.Status == Status.Updated)); } If I add " await " preceding the " _commands.Received().UpdateAsync ", it throws a null reference exception. How can I stop this happening, or is await not necessary? 回答1: I found an answer here. Received.InOrder(async () => { await