async-await

On Android device UI update happens only after user interaction

早过忘川 提交于 2019-12-24 06:08:02
问题 Interesting (at least for me) bug I found there. I am making an (prototype) app, it does some web requests and returns simple data. There is ObservableCollection<DownloadbleEntity> which is updated dynamicly (because DownloadbleEntity contains the image which we get by other requests, to output list element with an image). Here is layout part: <MvvmCross.Binding.Droid.Views.MvxListView android:id="@+id/searchlist" android:layout_width="fill_parent" android:layout_height="fill_parent" android

Task's continuation (built by async/await) is running on main thread in a WPF application, but on child in a console application

瘦欲@ 提交于 2019-12-24 05:56:57
问题 Assume I have a simple C# Console Application: class Program { static async void func() { Thread.CurrentThread.Name = "main"; await Task.Run(() => { Thread.CurrentThread.Name = "child"; Thread.Sleep(5000); }); Console.WriteLine("continuation is running on {0} thread", Thread.CurrentThread.Name); } static void Main(string[] args) { func(); Thread.Sleep(10000); } } When 5000 ms pass, we see the "continuation is running on child thread" message. When another 5000 ms pass, main thread finishes

Wait() causes UI thread to hang - when should Wait() be used?

我们两清 提交于 2019-12-24 05:39:14
问题 I have the following code that connects to a SignalR Hub private static async Task StartListening() { try { var hubConnection = new HubConnection("http://localhost:8080/"); IHubProxy hubProxy = hubConnection.CreateHubProxy("Broadcaster"); hubProxy.On<EventData>("notifyCardAccessEvent", eventData => { Log.Info(string.Format("Incoming data: {0} {1}", eventData.Id, eventData.DateTime)); }); ServicePointManager.DefaultConnectionLimit = 10; await hubConnection.Start(); Log.Info("Connected"); }

Correct Implementation of Async SerialPort Read

邮差的信 提交于 2019-12-24 05:39:13
问题 I have read a few threads here suggesting to use port.BaseStream.ReadAsync() with waith async / await. What is not clear to me is what is the best way to implement this? Do i still use the event_handler and just make it async / awaitable ? private async void myPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { byte[] buffer = new byte[myPort.BytesToRead]; await (myPort.BaseStream.ReadAsync(buffer, 0, buffer.Length)); } Or is the event handler ignored completely and instead i am

Task with result unknown type

家住魔仙堡 提交于 2019-12-24 04:13:04
问题 I'm working on a async CQS API The WebAPi method looks like this public async Task<object> Get([FromUri] Contract contract) { return await _invoker.Invoke(CreateDto<Query>(contract)); } Cannot implicitly convert type ' System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Customer>> ' to ' System.Threading.Tasks.Task<object> How can I return a task from result without knowing the type? This is the code that invokes the Generic typed class public Task<object> Invoke(Query query) {

How to return awaitable (Task?) that waits for an event in Dispatcher Thread

久未见 提交于 2019-12-24 04:09:04
问题 I have threads: UI thread with Dispatcher loop background thread that listens for messages in a queuing framework. when a message is received, an event is fired in the background thread: messageReceiver.Received += (sender, args) => ... In UI thread I would like to await a message, something like this: void ButtonClicked(object sender, RoutedEventArgs e) { await NextMessage(); //should return when messageReceiver.Received is fired } How to implement awaitable NextMessage method, so it does

Get Value Back from AWS lambda.invoke synchronously

时间秒杀一切 提交于 2019-12-24 04:01:59
问题 I'm attempting to call an AWS Lambda function from another Lambda function using the invoke method with a RequestResponse invocation type and retrieve a value returned from the Lambda. When I call the lambda.invoke using await the callback still appears to be called asynchronously. I'd like for the values I need to be available on the next line of code, hence the synchronous requirement. However, in the code below in the logs I see the "Data out of Callback" entry occur prior to the "Data in

Get Value Back from AWS lambda.invoke synchronously

会有一股神秘感。 提交于 2019-12-24 04:01:06
问题 I'm attempting to call an AWS Lambda function from another Lambda function using the invoke method with a RequestResponse invocation type and retrieve a value returned from the Lambda. When I call the lambda.invoke using await the callback still appears to be called asynchronously. I'd like for the values I need to be available on the next line of code, hence the synchronous requirement. However, in the code below in the logs I see the "Data out of Callback" entry occur prior to the "Data in

Queuing BankgroundJob with Hangfire within an async action in ASP.NET MVC freeze the application

ⅰ亾dé卋堺 提交于 2019-12-24 03:30:47
问题 I have this action on one of my controllers which is called by another method which has been called also by another action. All works fine, unless I try to en-queue with Hangfire some jobs: _bankClient.FetchAndEnsureTransactionsAsync and _bankClient.RefreshItemAsync . This is causing the application to freeze (the client, browser, stops while the server is still running). I suppose is some weird deadlock , but nothing I've tried seems to make it work! Would someone know how to solve this

Queuing BankgroundJob with Hangfire within an async action in ASP.NET MVC freeze the application

雨燕双飞 提交于 2019-12-24 03:30:03
问题 I have this action on one of my controllers which is called by another method which has been called also by another action. All works fine, unless I try to en-queue with Hangfire some jobs: _bankClient.FetchAndEnsureTransactionsAsync and _bankClient.RefreshItemAsync . This is causing the application to freeze (the client, browser, stops while the server is still running). I suppose is some weird deadlock , but nothing I've tried seems to make it work! Would someone know how to solve this