async-await

How to perform async ModelState validation with FluentValidation in Web API?

筅森魡賤 提交于 2020-01-01 12:27:11
问题 I setup a web api project to use FluentValidation using the webapi integration package for FluentValidation. Then I created a validator that uses CustomAsync(...) to run queries against the database. The issue is that the validation seems to deadlock when awaiting for the database task. I did some investigation, it seems that the MVC ModelState API is synchronous, and it calls a synchronous Validate(...) method that makes FluentValidation to call task.Result , causing the deadlock. Is it

TPL Break on unhandled exceptions

心已入冬 提交于 2020-01-01 12:07:15
问题 I am using async await as well as Task.Factory.StartNew in my application but one thing that i noticed changed is that visual studio is no more breaking when an unhandled exception occured Here is what i mean by before using await but after i turn a method into a Task and use await It is only captured in the output area in visual studio... BTW : It is very strange for me as i am new to .Net4.5 please excuse me if failed to illustrate what i need specifically but again what i want to know is

NUnit async test causing AppDomainUnloadedException

為{幸葍}努か 提交于 2020-01-01 09:58:11
问题 I have a .NET 4.5 WCF service with async operations. I have integration tests which constructs the service host using NetNamedPipeBinding and hits the operation via a client. However, each test like this always causes NUnit to report the following: System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion. Everything looks

ConfigureAwait: On which thread is the exception handled?

自古美人都是妖i 提交于 2020-01-01 09:55:16
问题 When you await a Task , the continuation by default runs on the same thread. The only time you ever actually need this is if you're on the UI thread, and the continuation needs to run on the UI thread as well. You can control this by using ConfigureAwait , e.g.: await SomeMethodAsync().ConfigureAwait(false); ...which can be useful to offload work from the UI thread that doesn't need to run there. (But see Stephen Cleary's comment below.) Now consider this bit of code: try { await

Starting async method as Thread or as Task

随声附和 提交于 2020-01-01 09:21:48
问题 I'm new to C# s await/async and currently playing around a bit. In my scenario I have a simple client-object which has a WebRequest property. The client should send periodically alive-messages over the WebRequest s RequestStream . This is the constructor of the client-object: public Client() { _webRequest = WebRequest.Create("some url"); _webRequest.Method = "POST"; IsRunning = true; // --> how to start the 'async' method (see below) } and the async alive-sender method private async void

Running Async Task unit tests with TFS 2010

烂漫一生 提交于 2020-01-01 07:07:23
问题 I am writing an application that is written in VS 2012 targeting .NET 4.0 using the Async library. My auto builds run on a TFS 2010 build agent that has VS 2012 and .NET 4.5 installed. I read everywhere that if your unit test is async it must have the async Task TestMethod() signature (rather than async void TestMethod() ). However when I do that my build server gives me this error for that method: Test method marked with the [TestMethod] attribute must be non-static, public, does not return

KeyVault GetSecretAsync never returns

倾然丶 夕夏残阳落幕 提交于 2020-01-01 06:38:24
问题 The sample code for working with KeyVault inside a web application has the following code in it: public static async Task<string> GetSecret(string secretId) { var secret = await keyVaultClient.GetSecretAsync(secretId); return secret.Value; } I've incorporated the KeyVaultAccessor object included in the sample in my application in order to test it. The call is executed as part of a query to one of my web api controller methods: var secret = KeyVaultAccessor.GetSecret("https://superSecretUri")

Nested Async/Await Nodejs

感情迁移 提交于 2020-01-01 05:24:06
问题 Cannot seem to figure out why this is not working for me. I have a parent function that performs an AWAIT on a child load process... the LOAD process in turn calls another AWAIT called LOADDATA... so basically like this: module.exports = async function () { try { await load(); } catch (ex) { console.log(ex); logger.error(ex); } }; async function load() { return await new Promise((resolve, reject) => { TableImport.findAll().then((tables) => { for (let table of tables) { await loadData(table

Saved files sometime only contains NUL-characters

北城以北 提交于 2020-01-01 05:22:07
问题 We have a problem in our Windows 8.1 application (WinRT) that sometimes our saved file gets corrupt. The files have a correct file size, but the file only contains NUL-characters. The file should contain a serialized object as XML. In an attempt to find the issue we do not overwrite the file, we do the following: Serialize the current object to a temp file. Check the content of the temp file Copy the current file (to .timestamp.xml.bak) Move/replace the temp file to the current file Most of

Async tasks are evaluated twice

前提是你 提交于 2020-01-01 04:54:12
问题 I use the following method to do some tasks asynchronously and at the same time: public async Task<Dictionary<string, object>> Read(string[] queries) { var results = queries.Select(query => new Tuple<string, Task<object>>(query, LoadDataAsync(query))); await Task.WhenAll(results.Select(x => x.Item2).ToArray()); return results .ToDictionary(x => x.Item1, x => x.Item2.Result); } I want the method to call LoadDataAsync for each string in the array at the same time, then wait until all tasks are