Encountered problems with cross threading when binding a USerName property in a Singleton class using WCF.
The UserName property in the singleton is updated using a BeginGetUserName WCF method with a EndGetUserName and this caused a cross thread exception because the UserName was being updated outside the UI thread. Solution was to pass a dispatcher object into the Singleton from MainPAge code behind and then use a BeginInvoke method to update the Username in the EndGetUserName method. Hence :
private void GetUserName()
{
Svc.BeginGetUserName(new AsyncCallback(GetUserNameCallback), Svc);
}
private void GetUserNameCallback(IAsyncResult ar)
{
IDriveParameterService s = (IDriveParameterService)ar.AsyncState;
dispatcher.BeginInvoke(delegate()
{
UserName = s.EndGetUserName(ar);
}
);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment