async-ctp

webClient.DownloadStringTaskAsync().Wait() freezes the UI

人盡茶涼 提交于 2019-12-08 13:03:54
问题 I am using silverlight 4, and the new async CTP. private void button1_Click(object sender, RoutedEventArgs e) { WebClient wb = new WebClient(); var t = wb.DownloadStringTaskAsync("http://www.google.com"); t.Wait(); } This code causes the UI to freeze. On the other hand, this code works fine : private void button1_Click(object sender, RoutedEventArgs e) { WebClient wb = new WebClient(); var t = Task.Factory.StartNew(() => Debug.WriteLine("Doing something")); t.Wait(); } Whats the difference

How can I use the AsyncCTP with an TFS APM Method (Query.Begin/EndQuery)?

天涯浪子 提交于 2019-12-08 05:35:54
问题 Would like to try using AsyncCTP with TFS. Currently have a long running method that calls RunQuery on a TFS Query instance. Query exposes the APM methods BeginQuery() and EndQuery(). As I understand it, the recommended approach to wrap these using AsyncCTP is something like: (example from docs) Task<int>.Factory.FromAsync(stream.BeginRead, stream.EndRead, buffer, offset, count, null); Further, have wrapped it in an extension method as in the docs so my actual method looks like: public static

How can I use the AsyncCTP with an TFS APM Method (Query.Begin/EndQuery)?

房东的猫 提交于 2019-12-06 16:15:11
Would like to try using AsyncCTP with TFS. Currently have a long running method that calls RunQuery on a TFS Query instance. Query exposes the APM methods BeginQuery() and EndQuery(). As I understand it, the recommended approach to wrap these using AsyncCTP is something like: (example from docs) Task<int>.Factory.FromAsync(stream.BeginRead, stream.EndRead, buffer, offset, count, null); Further, have wrapped it in an extension method as in the docs so my actual method looks like: public static Task<WorkItemCollection> RunQueryAsync(this Query query) { if (query== null) throw new

Why is the async CTP performing poorly?

久未见 提交于 2019-12-06 01:04:19
问题 I don't really understand why await and async don't improve the performance of my code here like they're supposed to. Though skeptical, I thought the compiler was supposed to rewrite my method so that the downloads were done in parallel... but it seems like that's not actually happening. ( I do realize that await and async do not create separate threads; however, the OS should be doing the downloads in parallal, and calling back my code in the original thread -- shouldn't it? ) Am I using

Async CTP Bug - Task Never Completes

南笙酒味 提交于 2019-12-05 12:42:32
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; // This line is never hit. } private async Task Sleep() { await TaskEx.Run(() => System.Threading.Thread

How to write simple async method?

≡放荡痞女 提交于 2019-12-05 10:40:21
问题 Using latest CTP5 with async/await keywords, I wrote some code, which apparently cannot compile: class Program { public class MyClass { async public Task<int> Test() { var result = await TaskEx.Run(() => { Thread.Sleep(3000); return 3; }); return result; } } static void Main(string[] args) { var myClass = new MyClass(); //The 'await' operator can only be used in a method or lambda marked with the 'async' modifier error ??!! int result = await myClass.Test(); Console.ReadLine(); } } What is th

Returning Void in Async method from WEB API Controller

坚强是说给别人听的谎言 提交于 2019-12-05 04:05:28
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> bodyparts = await Request.Content.ReadAsMultipartAsync(stream); IDictionary<string, string>

Code Contracts and Asynchrony

不羁的心 提交于 2019-12-04 17:05:30
问题 What is the recommended way for adding postconditions to async methods which return Task<T> ? I have read the following suggestion: http://social.msdn.microsoft.com/Forums/hu-HU/async/thread/52fc521c-473e-4bb2-a666-6c97a4dd3a39 The post suggests implementing each method as synchronous, contracting it, and then implementing an async counterpart as a simple wrapper. Unfortunately I don't see this as a workable solution (perhaps through my own misunderstanding): The async method, although

Calling an async method from a non-async method

淺唱寂寞╮ 提交于 2019-12-04 06:57:39
Every variation on the following code that I try doesn't work - whether DoSomething() : void and is called as written, or DoSomething() : Task and is called with TaskEx.RunEx() , some attempt involving .GetAwaiter().GetResult() . Errors seen include: "Start may not be called on a task with null action" , "RunSynchronously may not be called on a task unbound to a delegate" , and "The task has not yet completed" . class Program { static void Main(string[] args) // Starting from a non-async method { DoSomething(); Console.WriteLine("Press any key to quit."); Console.ReadKey(); } static async void

How to write simple async method?

不羁岁月 提交于 2019-12-03 22:58:05
Using latest CTP5 with async/await keywords, I wrote some code, which apparently cannot compile: class Program { public class MyClass { async public Task<int> Test() { var result = await TaskEx.Run(() => { Thread.Sleep(3000); return 3; }); return result; } } static void Main(string[] args) { var myClass = new MyClass(); //The 'await' operator can only be used in a method or lambda marked with the 'async' modifier error ??!! int result = await myClass.Test(); Console.ReadLine(); } } What is th reason of "The 'await' operator can only be used in a method or lambda marked with the 'async'