how to use thread for an function in wpf using

Posted by Sudhakar_A under C# on 9/30/2013 | Points: 10 | Views : 1246 | Status : [Member] | Replies : 1
I want to send 4 packet to ma device connected to the com port.
I have written port.write for all packet in an single button click event.
Using datareceived event and delegates,I catch the device Response in the com port and display it on the richtextbox in ma wpf application.
In ma button click event all the packet are sending one after the another till the device response back.
please help that after each packet, the next packet wait for the response of the previous one and then go.
I have an idea to use thread for each individual packet.
If thread is the only solution then ......let me know to create thread for each function i.e packet1 in different thread. packet2 in thread,packet3 in thread and soon.
any other simple solution,will also be apprecitate.
Thnk's in advance:):)


Posted by: Allemahesh on: 10/1/2013 [Member] [MVP] Silver | Points: 25

Dear Sudhakar,

I thing you have used the delegates to get response form you com port. So thread will not work in you case. You will only use the thread for multitasking applications.
So what I suggested is create a static global variable. Send the one packet to device then update this variable to true. At the same time let you com port will check response. Once the response is got then update the variable to false.
Now before sending the second and more packets, check if variable is true or false.

If static variable is false, then send the second packet else wait till the static variable is false.

This will help to solved you issue.

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response