async-ctp

Alternative for Task.Wait in UI thread

心不动则不痛 提交于 2021-02-07 12:58:26
问题 I know it is bad to call Task.Wait in UI thread. It causes a deadlock. Please refer to Constructor invoke async method Await, and UI, and deadlocks! Oh my! Take the following code: public MainPage() { this.InitializeComponent(); step0(); step1(); } private async Task step0() { await Task.Delay(5000); System.Diagnostics.Debug.WriteLine("step 0"); } private async Task step1() { await Task.Delay(3000); System.Diagnostics.Debug.WriteLine("step 1"); } } How can I ensure that "step 0" is always

DownloadStringTaskAsync on WP7 hangs when retrieving Result

戏子无情 提交于 2020-02-07 03:13:45
问题 I converted a bunch of WP7 code to use DownloadStringTaskAsync instead of DownloadStringAsync using the Async CTP SP1. It wasn't working so I boiled down my code a bunch and ended up with these 2 lines: var wc = new WebClient(); var result = wc.DownloadStringTaskAsync("http://www.weather.gov").Result; If I run this method with a console app on my windows machine. Its works as I expect and I get a string with the contents of weather.gov. If I run the same 2 lines in the constructor of App in a

UserState using WebClient and TaskAsync download from Async CTP

女生的网名这么多〃 提交于 2020-01-17 04:29:06
问题 I'm currently working with the Async CTP and need to convert this code into code where I can use Task.WhenAll(). What I did until now was using the UserState object and put my identifier (AID) into it and then use it in the completed event. However the wc.DownloadFileTaskAsync methode doesn't have an overload with UserState. What can I do? for (int i = 0; i < SortedRecommendations.Count; i++) { string tempfilepath = filepath + SortedRecommendations[i].Aid + ".jpg"; if (File.Exists

Async CTP and Windows Azure Support

你离开我真会死。 提交于 2020-01-06 02:26:20
问题 Quick question, couldn't find a answer via google... Does the Windows Azure platform support Async CTP? Is it a matter of copying references? 回答1: You can install the Async CTP and then create an Azure project that references it. The Async CTP libraries are under My Documents - Microsoft Visual Studio Async CTP - Samples. Just use the regular AsyncCtpLibrary.dll for web or worker roles. I believe it'll be copied by default into your bin folder. The async/await pattern can be used because it

Async CTP Bug - Task Never Completes

微笑、不失礼 提交于 2020-01-02 05:38:09
问题 Firstly a forward apology: I cannot isolate the following bug into a simple console application. However, in my relatively simple ASP.NET Web Forms application, the following code will cause the current thread to block indefinitely: public class MyModule : IHttpModule { public void Dispose() { } public void Init(System.Web.HttpApplication context) { context.BeginRequest += this.Context_BeginRequest; } private void Context_BeginRequest(object sender, EventArgs e) { Sleep().Wait(); var x = 2; /

Returning Void in Async method from WEB API Controller

女生的网名这么多〃 提交于 2020-01-02 02:25:10
问题 I have this async method inside ASP.NET MVC 4 WEB API Controller that I got from this blog: http://www.strathweb.com/2012/04/html5-drag-and-drop-asynchronous-multi-file-upload-with-asp-net-webapi/ public async Task<IList<RecivedFile>> Post() { List<RecivedFile> result = new List<RecivedFile>(); if (Request.Content.IsMimeMultipartContent()) { try { MultipartFormDataStreamProvider stream = new MultipartFormDataStreamProvider(HostingEnvironment.MapPath("~/USER-UPLOADS")); IEnumerable<HttpContent

Projection using async delegate/lambda

十年热恋 提交于 2019-12-30 13:11:45
问题 The following code will not compile against the Async CTP in Visual Studio 2010: Enumerable.Range(1, 5).Select(async x => { await TaskEx.Delay(100); return 5; }); The compilation error is as follows: Test.cs(40,13): error CS1928: 'System.Collections.Generic.IEnumerable<int>' does not contain a definition for 'Select' and the best extension method overload 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)' has some

Projection using async delegate/lambda

限于喜欢 提交于 2019-12-30 13:11:44
问题 The following code will not compile against the Async CTP in Visual Studio 2010: Enumerable.Range(1, 5).Select(async x => { await TaskEx.Delay(100); return 5; }); The compilation error is as follows: Test.cs(40,13): error CS1928: 'System.Collections.Generic.IEnumerable<int>' does not contain a definition for 'Select' and the best extension method overload 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)' has some

Task chaining without TaskCompletionSource?

牧云@^-^@ 提交于 2019-12-30 06:50:23
问题 I'm converting some async/await code to chained tasks, so I can use it in the released framework. The await code looks like this public async Task<TraumMessage> Get() { var message = await Invoke("GET"); var memorized = await message.Memorize(); return memorized; } where Task<TraumMessage> Invoke(string verb) {} Task<TraumMessage> Memorize() {} I was hoping to chain Invoke and Memorize to return the task produced by Memorize , but that results in a Task<Task<TraumMessage> . The solution i've

How to better understand the code/statements from “Async - Handling multiple Exceptions” article?

我只是一个虾纸丫 提交于 2019-12-29 07:17:09
问题 Running the following C# console app class Program { static void Main(string[] args) { Tst(); Console.ReadLine(); } async static Task Tst() { try { await Task.Factory.StartNew (() => { Task.Factory.StartNew (() => { throw new NullReferenceException(); } , TaskCreationOptions.AttachedToParent ); Task.Factory.StartNew ( () => { throw new ArgumentException(); } ,TaskCreationOptions.AttachedToParent ); } ); } catch (AggregateException ex) { // this catch will never be target Console.WriteLine("**