asynchronous

Async Method skips await

▼魔方 西西 提交于 2021-02-05 11:52:43
问题 I have the following code: public async Task<string> GetData(Uri source) { if (client.IsBusy == true) client.CancelAsync (); Task<string> tskResult = client.DownloadStringTaskAsync (source); string strResult = await tskResult; return strResult; } When I step through this method starting with Task<string>... the debugger jumps over return strResult; And the value of strResult is null. Why does this happen? Thanks. PS: I am calling this method like this: StringBuilder strBuild = new

DeadLock on task.Wait() with Task which edit UI

寵の児 提交于 2021-02-05 10:40:39
问题 I'm trying to find some solutions to my problem here, but with no result (or I just do not get them right) so if anyone could help / explain i will be really gratefull. I'm just developing a tool for system administrators using Win Form and now I need to create a continuous ping on the selected machine which is running on the background. There is an indicator for Online status on UI which I need to edit with background ping. So right now I'm in this state: Class A (Win form): ClassB

Queuing asynchronous task in C#

霸气de小男生 提交于 2021-02-05 09:59:49
问题 I have few methods that report some data to Data base. We want to invoke all calls to Data service asynchronously. These calls to data service are all over and so we want to make sure that these DS calls are executed one after another in order at any given time. Initially, i was using async await on each of these methods and each of the calls were executed asynchronously but we found out if they are out of sequence then there are room for errors. So, i thought we should queue all these

TypeError from Python 3 async for loop

妖精的绣舞 提交于 2021-02-05 09:35:20
问题 I'm learning about Python's relatively new async features. I found this in PEP 492: The following is a utility class that transforms a regular iterable to an asynchronous one. While this is not a very useful thing to do, the code illustrates the relationship between regular and asynchronous iterators. class AsyncIteratorWrapper: def __init__(self, obj): self._it = iter(obj) def __aiter__(self): return self async def __anext__(self): try: value = next(self._it) except StopIteration: raise

Unable to resolve promise rejection and send array as response

守給你的承諾、 提交于 2021-02-05 08:23:26
问题 I am trying to handle two queries within each other. exports.get_users = (req, res) => { SubscriptionPlan.find() .then((result) => { if (!result) { return res.status(400).json({ message: "unable to process" }); } let modifiedData = []; result.forEach(async (data) => { if (data.processStatus === "active") { await Users.findById(data.userId).then( (response) => { console.log(response) modifiedData.push(response); res.json(modifiedData) } ); } }); }) .catch((err) => console.log(err)); }; My

How exactly are the function calls ordered in an asynchronous JavaScript program?

▼魔方 西西 提交于 2021-02-05 07:49:05
问题 I am learning the concept of asynchronous programming in JavaScript (JS). But, I am having a hard time understanding the same. For the last few days, I had been reading various articles on the internet to understand it, but I am unable to grasp the idea. So, here are the doubts I have: setTimeout(function(){ alert("Hello 1"); }, 3000); // .....(i) console.log("Hi!"); // .....(ii) setTimeout(function(){ alert("Hello 2"); }, 2000); // .....(iii) Consider the above code. I learnt that JS uses a

Awaiting Task.Run with async method does not throw exception on correct thread

与世无争的帅哥 提交于 2021-02-05 07:21:25
问题 When running the test method below, I found that even though I await a task that throws an exception, the test passes. Furthermore, a separate window pops up saying "QTAgent.exe has stopped working". This indicates that the exception is not propagated to the thread running the test and instead kills a separate thread. I would like to know why this happens. Also, since this doesn't appear to work as intended, how should I run an async method on a thread pool thread? Note that if I change it so

Why is .json() asynchronous? [duplicate]

末鹿安然 提交于 2021-02-05 05:52:28
问题 This question already has answers here : Why does .json() return a promise? (4 answers) Closed last year . I've been following a tutorial and came across the following code snippet: const myAsyncFunction = async () => { const usersResponse = await fetch( 'https://jsonplaceholder.typicode.com/users' ) const userJson = await usersResponse.json(); const secondUser = userJson[1]; console.log(secondUser); const posts = await fetch ( 'https://jsonplaceholder.typicode.com/posts?userId=' + secondUser

How to find out which of these sites failed

旧街凉风 提交于 2021-02-05 05:41:03
问题 I have an asyncronous task that goes out to several websites parses some data and returns the data when its finished. In the event that one or more of the websites fail - I need to find out which ones failed. Is this possible? Here is some example code I have: The controller public async Task<ActionResult> Index() { Models.WebSite ws = new Models.WebSite(); List<Task<string>> webList = new List<Task<string>>(); webList.Add(ws.GetWebsiteInfoAsync("http://website1.com")); webList.Add(ws

How to find out which of these sites failed

耗尽温柔 提交于 2021-02-05 05:39:10
问题 I have an asyncronous task that goes out to several websites parses some data and returns the data when its finished. In the event that one or more of the websites fail - I need to find out which ones failed. Is this possible? Here is some example code I have: The controller public async Task<ActionResult> Index() { Models.WebSite ws = new Models.WebSite(); List<Task<string>> webList = new List<Task<string>>(); webList.Add(ws.GetWebsiteInfoAsync("http://website1.com")); webList.Add(ws