views:

29

answers:

1

I've implemented ICallbackEventHandler to handle data sent from the browser's javascript. (The user clicks something, causing eventArgument to be sent to the server. The server invokes a service to obtain regarding that value.) Everything works great so far, but I actually need to invoke three different services with the same eventArgument. Depending on when/if each service responds, its results need to be sent to the browser for it to augment the display. I'm thinking of creating a thread for each service request. When/if it responds, then I'd send those results to the browser too.

What would be a good way to accomplish this?

//ICallbackEventHandler implementation 
public void RaiseCallbackEvent(String eventArgument)
{
   returnValue = GetDataFromService1(eventArgument);
}

public String GetCallbackResult()
{
   return returnValue;
}
A: 

The easiest way to implement this would be to implement javascript in the browser that polls for results from each service, given that each may return at a different time.

Another option might be Reactive Extensions for .NET (Rx). Rx offers "push" notifications to a browser using Observable collections implemented in .NET and "emitted" to javascript.

Dave Swersky
> easiest way would be to implement javascript that polls
Mark Maslar
Not sure that implementing a polling mechanism in JS would be so easy.
Mark Maslar
>Rx offers "push" notifications to a browser
Mark Maslar
Can you point me to any examples of that? I'm only finding examples of C# observing browser events or Javascript doing same. Thx!
Mark Maslar
@Mark: You can use setTimeout() to call a function repeatedly, which would amount to a polling mechanism: http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/ .NET Rx: http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx
Dave Swersky
Thanks Dave, both options seem to be viable. I'm leaning towards Rx; pushing info from the server to the browser as it becomes available.
Mark Maslar
@Mark: Glad I could help- if you do end up using Rx leave a comment, let me know how it goes. I'm interested in Rx myself...
Dave Swersky