Questions tagged [iasyncresult]

Questions аbout IAsyncResult .net interface that represents the status of an asynchronous operation.

Questions аbout IAsyncResult .net interface that represents the status of an asynchronous operation.

The IAsyncResult interface is implemented by classes containing methods that can operate asynchronously. It is the return type of methods that initiate an asynchronous operation, such as FileStream.BeginRead, and it is passed to methods that conclude an asynchronous operation, such as FileStream.EndRead. IAsyncResult objects are also passed to methods invoked by AsyncCallback delegates when an asynchronous operation completes.

An object that supports the IAsyncResult interface stores state information for an asynchronous operation and provides a synchronization object to allow threads to be signaled when the operation completes.

http://msdn.microsoft.com/en-us/library/system.iasyncresult.aspx

112 questions
16
votes
2 answers

Two questions about AsyncCallback and IAsyncResult pattern

Two questions on the callback pattern with AsyncCallback and IAsyncResult. I changed the question with a code example: using System; using System.Collections.Generic; using System.Text; namespace TestAsync { class Program { private…
Gerard
  • 13,023
  • 14
  • 72
  • 125
15
votes
3 answers

Too many arguments in BeginXXX for FromAsync?

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 =…
s d
  • 2,666
  • 4
  • 26
  • 42
13
votes
2 answers

What is a proper implementation of the IAsyncResult interface?

I'm looking into adding some flexibility to a class that I've created which establishes a connection to a remote host and then performs an exchange of information (a handshake). The current implementation provides a Connect function which…
Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151
13
votes
3 answers

IAsyncResult vs ThreadPool

I've just come across IAsyncResult recently and have played with it for quite some time. What I'm actually wondering is why use IAsyncResult when we have a way better alternative ThreadPool there? From my current understanding about both of them, I…
user1928346
  • 513
  • 6
  • 21
10
votes
4 answers

How to create an IAsyncResult that immediately completes?

I am implementing an interface which requires implementations of BeginDoSomething and EndDoSomething methods. However my DoSomething isn't really long-running. For simplicity assume DoSomething only compares two variables and return whether a >…
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221
9
votes
4 answers

HttpWebRequest.EndGetResponse throws a NotSupportedException in Windows Phone 7

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:…
7
votes
2 answers

OK to do heavy processing in async callbacks?

Is it OK to do heavy processing in .NET's asynchronous callbacks, hogging them for multiple seconds before returning? Or am I depriving the OS / the runtime of important resources? For example, consider TcpListener.BeginAcceptSocket. My callback…
Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
6
votes
2 answers

Implementing IAsyncResult explicitly

I am generally wary of implementing interfaces partially. However, IAsyncResult is a bit of a special case, given that it supports several quite different usage patterns. How often do you use/see used the AsyncState/AsyncCallback pattern, as opposed…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
6
votes
3 answers

Synchronous and asynchronous callbacks

I get confused with some terms while reading MSDN documents and code samples. What are callbacks in C#? In particular, what are synchronous and asynchronous callbacks ? Please explain these from a layman's point of view. Also, please explain the…
user160677
  • 4,233
  • 12
  • 42
  • 55
5
votes
1 answer

C# How do I pass more than just IAsyncResult into AsyncCallback?

How do I pass more than just the IAsyncResult into AsyncCallback? Example code: //Usage var req = (HttpWebRequest)iAreq; req.BeginGetResponse(new AsyncCallback(iEndGetResponse), req); //Method private void iEndGetResponse(IAsyncResult iA, bool…
PiZzL3
  • 2,092
  • 4
  • 22
  • 30
5
votes
1 answer

Process Model minFreeThreads clarification

I have been modifying the .net process model to solve some throughput issues. I've read a lot of the articles out there but need some clarification on the minFreeThreads property. Does raising this value mean that more threads are reserved to…
Jeff Z
  • 307
  • 1
  • 2
  • 8
5
votes
1 answer

C#, IAsyncResult and the thread pool

I use the Action.BeginInvoke() method, does this use the thread pool or not? I have the following C# code: List hashList1 = hashList.Where((x, ind) => ind % 2 == 0).ToList(); List hashList2 = hashList.Where((x,…
tuinstoel
  • 7,248
  • 27
  • 27
5
votes
1 answer

Why doesn't my NamedPipeServerStream wait?

I'm working with a NamedPipeServerStream to communicate between two processes. Here is the code where I initialize and connect the pipe: void Foo(IHasData objectProvider) { Stream stream = objectProvider.GetData(); if (stream.Length > 0) …
Farnk
  • 244
  • 3
  • 12
5
votes
2 answers

How come Task implements IAsyncResult, but does not contain the AsyncWaitHandle member?

Maybe it is a silly question. The Task class is declared this way: public class Task : IThreadPoolWorkItem, IAsyncResult, IDisposable The IAsyncResult interface is declared like this: public interface IAsyncResult { object AsyncState { get; } …
vtortola
  • 34,709
  • 29
  • 161
  • 263
4
votes
4 answers

How can I easily chain two asynchronous requests together?

2013 Edit: async and await now make this trivial! :-) I've got some code that screen scrapes a website (for illustrative purposes only!) public System.Drawing.Image GetDilbert() { var dilbertUrl = new Uri(@"http://dilbert.com"); …
Ðаn
  • 10,934
  • 11
  • 59
  • 95
1
2 3 4 5 6 7 8