Hi guys
I'm a newbie with WCF services, and I'm trying to figure out if is there a better way to update a WPF UI element (like a Label control) when I'm calling asynchronously my WCF service.
Here's a piece of code:
private void button1_Click(object sender, RoutedEventArgs e)
{
int result;
CalculatorServiceClient proxy = new CalculatorServiceClient();
AsyncCallback addOperation = (async_result) =>
{
result = proxy.EndAdd(async_result);
Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(
delegate()
{
label1.Content = result.ToString();
}
)
);
proxy.Close();
};
proxy.BeginAdd(Convert.ToInt32(txtNumber1.Text), Convert.ToInt32(txtNumber2.Text), addOperation, null);
}
As you can see, I'm updating label1.Content with an asynchronous result, obtained by an AsyncCallback.
My question is, is there a better or more correct way to refresh an UI control inside this asynchronous callback operation?
thanks in advance!