I have a WCF service and consuming it in my silverlight 4 application. i have 5 async calls. how can i know that they have completed???
void service_StochSlowCompleted(object sender, StochSlowCompletedEventArgs e)
{
int count = e.Result.Count / 2;
for (int i = 0; i < count; i++)
{
Stoch.Add(e.Result[i]);
}
}
void service_MovingAvgCompleted(object sender, MovingAvgCompletedEventArgs e)
{
MA = e.Result;
}
void service_MomentumCompleted(object sender, MomentumCompletedEventArgs e)
{
PMO = e.Result;
}
void service_RSICompleted(object sender, RSICompletedEventArgs e)
{
RSI = e.Result;
}
void service_OBVCompleted(object sender, OBVCompletedEventArgs e)
{
OBV = e.Result;
}
public void Get_Data(ObservableCollection<double> high, ObservableCollection<double> low, ObservableCollection<double> open, ObservableCollection<double> close, ObservableCollection<double> volume, ObservableCollection<DateTime> date)
{
service.OBVAsync(0, close.Count - 1, close, volume);
service.RSIAsync(0, close.Count - 1, close, 9);
service.StochSlowAsync(0, close.Count - 1, high, low, close, 14, 3, 14);
service.MomentumAsync(0, close.Count - 1, close, 10);
service.MovingAvgAsync(0, close.Count - 1, close, 10);
Close = close;
Date = date;
}
public void Predict()
{
//some code uses the results returned from the serivce
}
and outside i have:
Prediction p = new Prediction();
p.Get_Data(high, low, open, close, volume, date);
p.Predict();
So .. please how can i know?????
You should Add an event named Get_DataCompleted to your Prediction class.
Raise this event when all service_*Comlpeted methods have been called. To do that, you may add a call at the end of the method that decrement an int and call raises the Get_DataCompleted when the int = 0.
Set the int to 5 at the begining of Get_Data.
You may throw an InvalidOperationException when Get_Data is called and the int is > 0. (Or abort previous calls, reinitialize, …)
Call p.Predict when the Get_DataCompleted is raised.
outside :