async

How to use RestSharp with async/await

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm struggling to find a modern example of some asynchronous C# code that uses RestSharp with async and await . I know there's been a recent update by Haack but I don't know how to use the new methods. Also, how can I provide a cancellation token so that the operation can be canceled (say, if a person is sick of waiting and presses the Cancel button in the app's UI). 回答1: Well, the update Haack is referring to has been made by me :) So let me show you how to use it, as it is actually very simple. Previously you had methods like

boost::asio::spawn yield as callback

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to rewrite a project using boost::asio::spawn coroutines. Some parts of the project cannot be changed. For example, the storage protocol library is also written with boost::asio , but without coroutines. The problem is how to convert yield_context into a normal callback (a boost::function object or a classical functor). This is what we have in the storage library API: void async_request_data(uint64_t item_id, boost::function< void(Request_result *) > callback); As we know from examples, the asio yield context can be used like this

Setup async Task callback in Moq Framework

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got an interface which declares Task DoSomethingAsync(); I'm using MoqFramework for my tests: [TestMethod()] public async Task MyAsyncTest() { Mock mock = new Mock (); mock.Setup(arg => arg.DoSomethingAsync()).Callback(() => { }); ... } Then in my test I execute the code which invokes await DoSomethingAsync() . And the test just fails on that line. What am I doing wrong? 回答1: Your method doesn't have any callbacks so there is no reason to use .CallBack() . You can simply return a Task with the desired values using .Returns() and Task

Node.js vs Async/await in .net

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can someone explain/ redirect me, what is the difference between Node.js's async model(non blocking thread) vs any other language for example c#'s asynchronous way of handling the I/O. This looks to me that both are same model. Kindly suggest. 回答1: Both models are very similar. There are two primary differences, one of which is going away soon (for some definition of "soon"). One difference is that Node.js is asynchronously single-threaded, while ASP.NET is asynchronously multi-threaded. This means the Node.js code can make some simplifying

node 7.6 async await issues with returning data

匿名 (未验证) 提交于 2019-12-03 02:43:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working on a simple TCP client for a server and am using the latest node 7.6 because of the async/await functions. I'm new to node and asynchronous coding, so I apologize if this is stupidly easy. I want to run a function that calls the callServer() function with specific parameters, wait until it finishes getting the data, and return the data as a variable. Here is my code: 'use strict' const net = require('net') var formattedJson = funcRequestToJson("Server.GetStatus", false) doThings() async function doThings() { var info = await

Is it possible to await an event instead of another async method?

匿名 (未验证) 提交于 2019-12-03 02:43:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my C#/XAML metro app, there's a button which kicks off a long-running process. So, as recommended, I'm using async/await to make sure the UI thread doesn't get blocked: private async void Button_Click_1(object sender, RoutedEventArgs e) { await GetResults(); } private async Task GetResults() { // Do lot of complex stuff that takes a long time // (e.g. contact some web services) ... } Occasionally, the stuff happening within GetResults would require additional user input before it can continue. For simplicity, let's say the user just has

Fire-and-forget with async vs “old async delegate”

匿名 (未验证) 提交于 2019-12-03 02:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 选择语言 中文(简体) 日语 英语 中文(繁体) 由 翻译 强力驱动 问题: I am trying to replace my old fire-and-forget calls with a new syntax, hoping for more simplicity and it seems to be eluding me. Here's an example class Program { static void DoIt ( string entry ) { Console . WriteLine ( "Message: " + entry ); } static async void DoIt2 ( string entry ) { await Task . Yield (); Console . WriteLine ( "Message2: " + entry ); } static void Main ( string [] args ) { // old way Action async = DoIt ; async . BeginInvoke ( "Test" , ar => { async . EndInvoke ( ar ); ar .

Asynchronous network programming with async/await

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For the past few years, I've developed client/server software using the Asynchronous Programming Model and sockets. This example on MSDN, although overcomplicated with synchronisation mechanisms such as ManualResetEvents, illustrates the concepts: you use a BeginXXX() and EndXXX() method pair for the connection and stream operations. This has the advantage of letting the thread pool assign threads as needed (e.g. when data is received) rather than having a dedicated thread per connection, which doesn't scale. Someone recently mentioned that

Async execution of shell command not working properly

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So, this is my code : - (void)runCmd:(NSString *)cmd withArgs:(NSArray *)args { NSLog(@"\nRunning ::\n\tCmd : %@\n\tArgs : %@",cmd, args); [theSpinner start]; if (task) { [task interrupt]; } else { task = [[NSTask alloc] init]; [task setLaunchPath:cmd]; [task setArguments:args]; [pipe release]; pipe = [[NSPipe alloc] init]; [task setStandardOutput:pipe]; NSFileHandle* fh = [pipe fileHandleForReading]; NSNotificationCenter* nc; nc = [NSNotificationCenter defaultCenter]; [nc removeObserver:self]; [nc addObserver:self selector:@selector

Does dispatch_async(dispatch_get_main_queue(), ^{…}); wait until done?

匿名 (未验证) 提交于 2019-12-03 02:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a scenario in my app, where I want to do some time consuming task which consists of some data processing as well as UI update, in a method. My method looks like this, - (void)doCalculationsAndUpdateUIs { // DATA PROCESSING 1 // UI UPDATE 1 // DATA PROCESSING 2 // UI UPDATE 2 // DATA PROCESSING 3 // UI UPDATE 3 } As it is time consuming I wanted to do the data processing on the background thread, using, dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, NULL), ^{ But as both data processing and UI updates are in