async

Downloading and saving a file Async in Windows Phone 8

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I download and save a file to IsolatedStorage asynchronously? I used WebClient first for the purpose, but I couldn't await till completion so I found some useful code here . However, this is also not in complete format. I found the function: public static Task DownloadFile(Uri url) { var tcs = new TaskCompletionSource (); var wc = new WebClient(); wc.OpenReadCompleted += (s, e) => { if (e.Error != null) tcs.TrySetException(e.Error); else if (e.Cancelled) tcs.TrySetCanceled(); else tcs.TrySetResult(e.Result); }; wc.OpenReadAsync(url);

Exception handling inside “async void” WPF command handlers

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm reviewing some WPF code of my colleagues, which is a library of UserControl -based components with a lot of async void event and command handlers. These methods currently do not implement any error handling internally. The code in a nutshell: private async void NewCommand_Executed(object sender, ExecutedRoutedEventArgs e) { // do some fake async work (and may throw if timeout Exceptions thrown but not observed inside NewCommand_Executed can only be handled on a global level (e.g., with AppDomain.CurrentDomain.UnhandledException ).

Asp.Net Core unit testing async controller

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this test: [Fact] public async void Can_Paginate() { //fake data var product1 = new Product { ProductId = 1, ProductName = "P1" }; var product2 = new Product { ProductId = 2, ProductName = "Product 2" }; var product3 = new Product { ProductId = 3, ProductName = "Product 3" }; var product4 = new Product { ProductId = 4, ProductName = "Product 4" }; var product5 = new Product { ProductId = 5, ProductName = "Product 5" }; var data = new List<Product> { product1, product2, product3, product4, product5 }.ToAsyncEnumerable(); var category1

RunAsync - How do I await the completion of work on the UI thread?

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When awaiting Dispatcher.RunAsync the continuation occurs when the work is scheduled, not when the work has completed. How can I await the work completing? Edit My original question assumed the premature continuation was caused by the design of the API, so here's the real question. When awaiting Dispatcher.RunAsync using an asynchronous delegate, using await within the delegate's code, the continuation occurs when the await is encountered, not when the work has completed. How can I await the work completing? Edit 2 One reason you may need to

VueJs Async loading templates

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I Am building my first VueJs App and I want to asynchronous load my template. In our framework we have our templates stored in a database, that's why. It is working until I have some nested dom-elements in my template without any data bound to it. So my my Vuejs is like: var app = new Vue({ el: '#app', data: { finish: false, template: null }, render: function(createElement) { if (!this.template) { return createElement('div', 'loading...'); } else { return this.template(); } }, mounted() { var self = this; $.post('myUrl', {foo:'bar'},

Async and await in MVC 4 Controller

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Every time I try to use the new Async and Await operators and return a collection of objects from a database I get an Invalid Operation exception. When I use it to only return a single Item it works fine. Controller Code: public async Task EnvironmentList () { EfEnvironmentDataAccess dataAccess = new EfEnvironmentDataAccess (); ICollection environments = await dataAccess . GetAllEnvironmentsAsync (); return PartialView ( environments ); } View Code: Table Dumps @Html . Action ( "EnvironmentList" , "Environment" ) @Html . Action (

Async for Bulk copy

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have quite a few datatable to bulkinsert into databasetable Due to large size, one table took 5 min to complete insert. 2 tables took me 10 min static void Main(string[] args) { DataTableBulkInsert(DataTable1); DataTableBulkInsert(DataTable2); } public static void DataTableBulkInsert(DataTable Table){ SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(myConnection); sqlBulkCopy.DestinationTableName = "dbo.DatabaseTable"; myConnection.Open(); sqlBulkCopy.WriteToServer(Table); myConnection.Close(); } I am now trying to do a async for Bulk insert, but

Async Void, ASP.Net, and Count of Outstanding Operations

匿名 (未验证) 提交于 2019-12-03 01:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to understand why an async void method in an ASP.Net application can result in the following exception, while it appears that async Task will not: System . InvalidOperationException : An asynchronous module or handler completed while an asynchronous operation was still pending I am relatively new to the world of async in .NET, but do feel like I've tried to run this one down via a number of existing resources, including all of the following: What's the difference between returning void and returning a Task? It's All

Wrap a function as an async task

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a function that I would like to wrap so that I can use the async/await pattern: wcfClientService.GetSomeString(parameter); It's a call from a WCF client that I'm trying to make asynchronous, but that's not important (I know WCF supports async, but let's assume we don't have access to the WCF code). I'm trying to wrap the method with the Task<T>.Factory.FromAsync method, but can't seem to get it right: private Task<string> WrapWcfServiceAsyncTask(uint parameter) { Func<uint, string> func = i => { return wcfClientService.GetSomeString

Starting multiple async/await functions at once and handling them separately

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do you start multiple HttpClient.GetAsync() requests at once, and handle them each as soon as their respective responses come back? First what I tried is: var response1 = await client.GetAsync("http://example.com/"); var response2 = await client.GetAsync("http://stackoverflow.com/"); HandleExample(response1); HandleStackoverflow(response2); But of course it's still sequential. So then I tried starting them both at once: var task1 = client.GetAsync("http://example.com/"); var task2 = client.GetAsync("http://stackoverflow.com/");