Resources » Code Snippets » Web Access

How to : Use the UserState property while making async WCF service calls

Updated: Category: Web Access
Author: Member Level: GoldPoints: 5

this code snippet decribes how to use the UserState property while making async WCF service calls in silverlight

In Silverlight, all the WCF service calls are asynchronous. After the call to the WCF service is completed, a Completed event is called at the silverlight UI side.Sometimes it becomes necessary to determine which task raised the Completed event.In this case you can use the "UserState" property to determine this.

For Example:

You want to download files from the server, and when the download is complete you want to show the filename that was downloaded. In the sample below "DownloadFileAsync" is the WCF function that is called asynchronously, "webServiceClient_DownloadFileCompleted" is the completed event for the WCF service call, "Filename" has the filename that is downloading.

private void DownloadSingleFile()
// Set user state here
webServiceClient.DownloadFileAsync(new Uri(downloadUrl), Filename);

void webServiceClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
txtStatus.Text = "File : " + e.UserState + " downloaded uccessfully !";


Note: The "UserState" property is of "Object" type so you can pass variable of any datatype.

Did you like this resource? Share it with your friends and show your love!

Responses to "How to : Use the UserState property while making async WCF service calls"

No responses found. Be the first to respond...


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India