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
4
votes
1 answer

Mocking a method that uses an asynchronous callback with moq

I'm unit testing some asynchronous code. I have tried to abstract it to make the issue more clear. My issue is that I want to set up the mocked Bar to execute Foo's private callback method after BeginWork returns. The callback is supposed to call…
Matt C.
  • 51
  • 4
4
votes
5 answers

Waiting on an IAsyncResult method that waits on another IAsyncResult (Chaining)

(can only use .NET 3.5 stock, so no Tasks, no Reactive Extensions) I have, what I thought to be a simple case, but I'm baffled at it. The short of it is that, I'm returning BeginGetRequestStream's IAsyncResult to the caller of BeginMyOperation(),…
4
votes
2 answers

Using BeginInvoke/EndInvoke in a multithreaded fashion. How do AsyncCallback, AsyncWaitHandle and IsCompleted interact?

Andreas Huber's answer to this question gave me an idea to implement Concurrent with async delegates instead of the ThreadPool. However, I am finding it harder to understand what's going on when an AsyncCallback is passed to BeginInvoke,…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
4
votes
1 answer

Reactive Extensions (Rx) and asynchronous class

I've read in this post: "The joy of Rx: The event-based asynchronous pattern vs IObservable" that the use of EBAP is discourage. What is the best way to design an asynchronous component with the new Rx extensions (something like the…
José F. Romaniello
  • 13,866
  • 3
  • 36
  • 38
4
votes
1 answer

c# Webrequest Post and GetResponse

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…
user2664502
  • 85
  • 2
  • 2
  • 5
4
votes
1 answer

Node and Lazy: How do I know when it's done?

I need to read a file line by line, and change a variable accordingly. I would normally write this in PHP... but I decided to take the challenge. I wrote: fs = require('fs'); Lazy = require('lazy'); path = require('path'); files =…
Merc
  • 16,277
  • 18
  • 79
  • 122
3
votes
1 answer

Does AsyncWaitHandle.WaitOne block the CLR thread? Or does it create an I/O completion port?

I have that question, does AsyncWaitHandle.WaitOne block the CLR thread? or does it create an I/O completion port? For example, when I run my application I launch a task 'A' that initializes some data, when new requests arrives, I want them to wait…
vtortola
  • 34,709
  • 29
  • 161
  • 263
3
votes
0 answers

How to make Async calls generate event for Powershell script?

I'm building event-oriented Powershell scripts. For asynchronous network operations, I usually use Begin/End calls such as BeginAcceptTcpClient / EndAcceptTcpClient for a System.Net.Sockets.TcpListener object. These calls use an IAsyncResult object…
Alain
  • 31
  • 1
3
votes
1 answer

Can AsyncCallback use a non-static delegate?

I'm using .net remoting, with asynchronous function calls to handle the ipc of my current project. I'm running into an issue where I'd like the client to: ASynchronously request information Continue loading the GUI When the ASynchronous call is…
greggorob64
  • 2,487
  • 2
  • 27
  • 55
3
votes
0 answers

Asynchronous connection not working after first failure

I am dealing with quite annoying issue, and I could not find any solution for this. I am calling WebRequest Connection, working under Unity C#; IAsyncResult startingTheCall = webRequest.BeginGetRequestStream(new …
user2426290
  • 382
  • 2
  • 14
3
votes
2 answers

Wait IAsyncResult function until complete

I need to create mechanism which waits IAsycnResult method till complete. How can i achieve this ? IAsyncResult result = _contactGroupServices.BeginDeleteContact( contactToRemove.Uri, ar => { try { …
3
votes
1 answer

How to send multiple acknowledgement to client using IHttpAsyncHandler in asp.net

I have implemented IHttpAsyncHandler in my class to perform 5-6 long running process in background and acknowledge to client on start of each task. Earlier I was using one session variable and updating it with current status of task, and giving…
3
votes
2 answers

Blocking until an event completes

How can you block until an asynchronous event completes? Here is a way to block until the event is called by setting a flag in the event handler and polling the flag: private object DoAsynchronousCallSynchronously() { int completed = 0; …
Jim
3
votes
2 answers

What are the strengths of the IAsyncResult pattern?

I feel that many classes (e.g. TcpClient, UdpClient, HttpListener) would've been much easier to understand and use if they were event driven. And IAsyncResult pattern is excessively hard to implement because it opens you to all kinds of weird use…
Ansis Māliņš
  • 1,684
  • 15
  • 35
2
votes
1 answer

Cancel asynchronous operation

I'm developing a class library that implements a protocol stack. There I have an asynchronous operation DoSomething that implements IAsyncResult. The user of this method can use BeginDoSomething and EndDoSomething. So long it's quite a common…
PVitt
  • 11,500
  • 5
  • 51
  • 85