I'm implementing a Silverlight application that uses WCF services heavily, I've got to the point now where occasionally there are several long service calls that block other service calls from running.
These service calls eventually time out. I'd like to see if its possible to a queue system that executes service calls one after another, this way long calls will hold up other calls but won't cause them to timeout.
I'm using service agents to wrap the service calls
public interface IExampleServiceAgent
{
void ProcessData(int a, string b, EventHandler<ProcessDataCompletedEventArgs> callback);
}
Public ExampleServiceAgent1 : IExampleServiceAgent
{
ExampleClient _Client = new ExampleClient();
public void ProcessData(int anInt, string aString, EventHandler<ProcessDataCompletedEventArgs> callback)
{
EventHandler<ProcessDataCompletedEventArgs> wrapper = null;
wrapper = (a,b) =>
{
callback(a,b);
_Client.ProcessDataCompleted -= wrapper;
}
_Client.ProcessDataCompleted += wrapper;
_Client.ProcessDataAsync(anInt,aString);
}
}
The above service agent would then be called from code as follows:
ServiceAgent.ProcessData(1,"STRING", (a,b) =>
{
if (b.Error != null)
{
//Handle Error
}
else
{
//DO something with the data
}
}
Is there a way I could put these service calls into a queue and execute them one by one?
I've tried wrapping them as Actions and adding them to a queue, but this does not wait for one to finish executing before starting the next one and although they do call the service correctly no data is returned to the calling ViewModel.