Solved

Using Rx to block asynchronous call but never calls event

Posted on 2011-03-01
2
657 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Login 17 51
how to check to see if datatable has headers or not 2 30
jQuery - following an example but can I save data server side? 20 50
Expression Evaluater 3 26
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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