Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Multi threading in windows phone C# ?

How to do multithreading when i call a wcf service . One thread should call service and one thread should show processing.
Posted
Comments

1 solution

Hi. I'm recommend to U to use Reactive Extensions for windows phone.
With help of this third-party library Rx(by the way it was wrriten by one of the LINQ founder ) you can achive such ability to call service on one thread and observe result on another.

For example let get json data from service:

C#
WebClient webClient = new WebClient();
            webClient.Headers.Add("uid", LoginData.LoginName);
            webClient.Headers.Add("pass", LoginData.Password);
            webClient.Headers.Add("logonType", "0");
            var eventStream = Observable.FromEventPattern<DownloadDataCompletedEventArgs>(webClient, "DownloadDataCompleted").
                SubscribeOn(Scheduler.NewThread).Select(newData => newData.EventArgs.Result);

eventStream.ObserveOn(System.Threading.SynchronizationContext.Current).Subscribe(OnDatareceived,
                //on error
                ex =>
                {
                    System.Windows.MessageBox.Show(ex.Message);
                    ViewModel.ViewModelLocator.Logger.Error(string.Empty, ex);
                });

            webClient.DownloadDataAsync(new Uri(ConfigurationManager.AppSettings["loginUrl"]));
            weakClient.Dispose();
            weakClient = null;

void OnDatareceived(byte[] data)
		{
			if(data!=null){
//convert byte array to string and deserialize it to object
}

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900