iasyncresult

Too many arguments in BeginXXX for FromAsync?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 10:34:55
I have an async method with the following signature: IAsyncResult BeginGetMyNumber(string foo, string bar, string bat, int bam, AsyncCallback callback, object state) I want to execute it using Factory.FromAsync like this: var result = Task<int>.Factory.FromAsync( instance.BeginGetMyNumber, instance.EndGetMyNumber, "foo", "bar", "bat", 100, /*bam*/ null); but I get the following error: Argument 1: cannot convert from 'method group' to 'System.Func' It seems there is no suitable overloaded FromAsync method http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskfactory.fromasync.aspx

C#, IAsyncResult and the thread pool

廉价感情. 提交于 2019-12-01 18:25:17
I use the Action<object>.BeginInvoke() method, does this use the thread pool or not? I have the following C# code: List<FileHash> hashList1 = hashList.Where((x, ind) => ind % 2 == 0).ToList(); List<FileHash> hashList2 = hashList.Where((x, ind) => ind % 2 == 1).ToList(); Action<object> oddWork = CalcHash; Action<object> evenWork = CalcHash; IAsyncResult evenHandle = evenWork.BeginInvoke(hashList1, null, null); IAsyncResult oddHandle = oddWork.BeginInvoke(hashList2, null, null); evenWork.EndInvoke(evenHandle); oddWork.EndInvoke(oddHandle); Is the thread pool used behind the scenes or not? Or

C#, IAsyncResult and the thread pool

﹥>﹥吖頭↗ 提交于 2019-12-01 17:44:53
问题 I use the Action<object>.BeginInvoke() method, does this use the thread pool or not? I have the following C# code: List<FileHash> hashList1 = hashList.Where((x, ind) => ind % 2 == 0).ToList(); List<FileHash> hashList2 = hashList.Where((x, ind) => ind % 2 == 1).ToList(); Action<object> oddWork = CalcHash; Action<object> evenWork = CalcHash; IAsyncResult evenHandle = evenWork.BeginInvoke(hashList1, null, null); IAsyncResult oddHandle = oddWork.BeginInvoke(hashList2, null, null); evenWork

HttpWebRequest.EndGetResponse throws a NotSupportedException in Windows Phone 7

我们两清 提交于 2019-11-30 03:53:21
问题 in a Silverlight-Windows Phone 7-project I am creating an HttpWebRequest, get the RequestStream, write something into the Stream and try to get the response, but I always get a NotSupportedException: "System.Net.Browser.OHWRAsyncResult.AsyncWaitHandle threw an exception of type 'System.NotSupportedException' My production code is far more complicated, but I can narrow it down to this small piece of code: public class HttpUploadHelper { private HttpWebRequest request; private RequestState

c# Webrequest Post and GetResponse

喜欢而已 提交于 2019-11-29 11:42:16
I am writing a program that will submit a XML to a website. The code written works fine, but sometimes it just stops working for some reason, throwing a System.Net.ProtocolViolationException. I can close the program and re-run - it starts working again just fine. Here is the code that I am using: private string Summit(string xml) { string result = string.Empty; StringBuilder sb = new StringBuilder(); try { WebRequest request = WebRequest.Create(this.targetUrl); request.Timeout = 800 * 1000; RequestState requestState = new RequestState(xml); requestState.Request = request; request.ContentType =

c# Webrequest Post and GetResponse

爷,独闯天下 提交于 2019-11-28 05:21:07
问题 I am writing a program that will submit a XML to a website. The code written works fine, but sometimes it just stops working for some reason, throwing a System.Net.ProtocolViolationException. I can close the program and re-run - it starts working again just fine. Here is the code that I am using: private string Summit(string xml) { string result = string.Empty; StringBuilder sb = new StringBuilder(); try { WebRequest request = WebRequest.Create(this.targetUrl); request.Timeout = 800 * 1000;