Multi-threading: l'UI and WebServices Call.
Hello,
I must build a Application that will use Webclient multiple times to retrieve every "t" seconds informations from a server.
Here is a small plan to show you what i'm doing in my application:
Step 1- Connect to the Web Client "USER_LOGIN" that returns me a GUID(user unique ID). I save it and keep it to use it in future Web Client calls.
Step 2- Connect to the Web Client "USER_GETINFO" using the GUID I saved before as parameter. This Web Service returns an array of strings holding all my personnal user information( my Name, Age, Email, etc...). => I save the array information this way: Textblock.Text = e.Result[2].
Step 3- Starting a Dispatcher.Timer with a 2 seconds Tick to start my Loop. (Purpose of this is to retrieve information and update it every 2 seconds)
3b- Connect to the Web Client "USER GETFRIEND", wich is in my Timer, giving him the GUID as parameter. It returns me an array filled with my friends informations(Name, email, message, etc...). I inserted this WebClient in the timer so my friend list refreshes every 2 seconds.
I am able to create all the steps without any error until step 3. When I call the "USER_GETFRIEND" Web Client I am facing two major problems:
- On one side I noticed that my number of Thread increased dramaticaly. => I always tought that when a WebClient had finished its instructions it would shut down by itself, but apparently that does not happen in Asyncronous calls.
-And on the other side I was surprised to see that using the same proxy for two Webclient calls(ie: if i declare test.MainSoapClient proxy = new test.MainSoapClient()), the data i would retrieve from "USER_GETFRIEND" e.Result, was sent directly to my "USER_GETINFO" array. And so my Name and Email adresses on the UI were replaced by the same value in the USER_GETFRIEND array. So my Name is changed to my friends email and so on...
I would like to know if it's possible to close a WebClient call(or Thread) that I am not using anymore to prevent any conflicts? Or if someone has any suggestion concerning my code and the way i should developp my application please feel free to propose.
Thank you.