Solved

Using Rx to block asynchronous call but never calls event

Posted on 2011-03-01
2
658 Views
Last Modified: 2013-11-12
I am trying to use Rx to block for an asynchronous webclient call so that I can treat the method as synchronous.  I got the method from here:

http://www.dotnetsolutions.co.uk/blogs/markrendle/archive/2010/06/11/functional-alchemy-making-silverlight-synchronous/
and it is discussed here (but I followed the simpler above example more than this one)
http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-2-converting.html

But it never seems to fire the event.  I can see using fiddler that the REST call is returned (with statuscode = 200 and with the expected data payload).

I am running this code in a Windows Forms application.  Does anyone have any ideas for me?  I feel like I am missing something simple here...

Thanks,
Nicole
WebClient client = new WebClient();

var blocker = Observable.FromEvent<OpenReadCompletedEventArgs>
	 (client, "OpenReadCompleted").SubscribeOnDispatcher().ToEnumerable();

string RESTGeocodeEndpoint = "http://myserver/ArcGIS/rest/services/geocode/GeocodeServer";
client.OpenReadAsync(new Uri(string.Format("{0}/findAddressCandidates?Single+Line+Input={1} {2}&Street={1}&f=json", RESTGeocodeEndpoint, street, postal)));

// Get the first element off the blocking Enumerable
var eventArgs = blocker.First().EventArgs;

//.......This next line is never called.......
if (eventArgs.Error != null)
{
	//log error
	return ;
}
else
{
//do some stuff and return
}

Open in new window

0
Comment
Question by:nicolees
  • 2
2 Comments
 

Author Comment

by:nicolees
ID: 35018512
I have modified my code so that it does not require any local resources to test it.  It now hits a public test url.  Thanks for any ideas.
WebClient client = new WebClient();

var blocker = Observable.FromEvent<OpenReadCompletedEventArgs>
	 (client, "OpenReadCompleted").SubscribeOn(System.Concurrency.Scheduler.NewThread).ToEnumerable();

client.OpenReadAsync(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer/findAddressCandidates?Address=380+New+York+Street&City=Redlands&State=CA&Zip=92373"));


// Get the first element off the blocking Enumerable
var eventArgs = blocker.First().EventArgs;

//.......This next line is never called.......
if (eventArgs.Error != null)
{
	//log error
	return ;
}
else
{
//do some stuff and return
}

Open in new window

0
 

Accepted Solution

by:
nicolees earned 0 total points
ID: 35018559
Okay so I think this question is irrelevant for non WPF and Silverlight applications because I can access OpenRead() instead.  I guess I just had my head too stuck in Silverlight lately.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question