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 to just calling EndInvoke, using AsyncWaitHandle, or polling IsCompleted (yuck)?
Related...
Andreas Huber's answer to this question gave me an idea to implement Concurrent<T> 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, especially when several threads have access to IAsyncResult. Unfortunately, this case doesn't seem...
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...
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");
var request = WebRequest.CreateDefault(dilbertUrl);
string html;
using (var webResponse = request.GetResponse())
using (var receiveStream = webResponse...
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 establishes the connection and then blocks waiting on a ManualResetEvent untill the two parties have...
I have a WCF web service that currently searches multiple, hard-coded dtSearch indices and then merges the resulting datasets to be returned back to the client. I have the following C# code:
public class Search : ISearch
{
delegate DataTable PDelegate(string term, int cid);
delegate DataTable CDelegate(string term, int sid);
...
Hi,
"session.identify" is a third party COM API that I call and have no access to. It performs a server query that, somehow, locks up occasionally (and thus halts the main program which is waiting for the result).
My attempt was to wrap it in an AsyncDelegate so I would be able to give it a timeout and after expiration of the timeout ...
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 IAsyncResult interface.
How can we implement it? (with very simple example)
Thanks in adv...
Let's say I have the following code :
ThreadPool.SetMinThreads(100, 100);
for (int i = 0; i < 100; i++)
{
var request = WebRequest.Create(url);
request.BeginGetResponse(ar =>
{
//inside AsynchCallBack method for request.BeginGetResponse()
var response = (HttpWebResponse)request.EndGetResponse(ar);
string html;
using (var ...
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;
AsynchronousObject obj = new AsynchronousObject();
obj.OnCompletedCallback += delegate {...
I have written an async UDP client to talk to a server at my company. When I run on my developer machine all is well. When I deploy to another machine I get a socket exception on EndReceive the first time I send data over the socket. My dev box is Win7 and I have deployed to both an XP SP3 machine and a Server 2003 R2 machine. Below ...
I made a WPF example that consumes a web service (www.webservicex.com/globalweather.asmx) in two different ways:
with events like this:
public Window1()
{
InitializeComponent();
DataContext = this;
Location = "loading...";
Temperature = "loading...";
RelativeHumidity = "loading...";
client.GetWeatherCompleted ...
Let's say I have code that uses the Asynchronous Programming Model, i.e. it provides the following methods as a group which can be used synchronously or asynchronously:
public MethodResult Operation(<method params>);
public IAsyncResult BeginOperation(<method params>, AsyncCallback callback, object state);
public MethodResult EndOperat...
Hi guys just wondering if somebody could help me try and correctly thread my application, I am constantly hitting an hurdle after another, I have never been to clued up on threading in applications. I have tryed following this http://www.developerfusion.com/code/4654/asynchronous-httpwebrequest/ tutorial.
basically I'm just trying to st...
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 PrimeNumberCalculator example of msdn)?
Thank you in advance.
Update
I managed to write my own prime nu...
i would like some help with the following. this is to do with Asynchronous sockets.
from the sender:
string stringData = "Welcome to my server server server";
byte[] message1 = Encoding.ASCII.GetBytes(stringData);
//MessageBox.Show(message1.Length.ToString());
client.BeginSend(message1, 0, message1.Length, SocketFlags.None, new Async...
I've never had much to do with async callbacks and delegates before on WinForms (i.e., not AJAX) so I'm hoping someone can help me out with what I'm trying to do here.
I'm logging into a third-party service over the web. The Login() method is of type Void.
Because this can take up to 10 seconds (very occasionally longer) I want to do t...
According to this article
The Begin Event Handler is Always Invoked
The second impliciation of
AsyncTimeout that I had not really
internalized until recently is that
the begin event handler for a
registered async task is always
invoked, even if the page has timed
out before ASP.NET gets around to
starting that task...
I have problem with Timeout, when I run a command through app, a timeout exception is thrown, but when I run it directly in sql there is no timeout exception!
my SP take about 11 min when I run it directly.
for solving this issue, I found below code here, but It doesn't work properly!
Immediately after beginExecute, IAsyncResult.iscompl...
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)
{
using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("Visualiz...