LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GUI hangs in multithreaded program

I have written an application that uses 2 threads. The main thread contains the GUI. The secondary thread implements an RS-422 communication driver. Both threads are set at normal priority. When I launch the application and if no RS-422 traffic is present I can't get into my GUI menus for about 5 seconds. After this initial annoying delay the GUI seems to be fine. If there is RS-422 communication there is no delay in using the GUI. I have experimented with setting the thread priority of the RS-422 thread to below normal. This eliminates the initial GUI delay when no RS-422 communication is present except does not give me the performance that I need. I have also experimented with the sleep policy in the GUI thread but this does not seem to
have any affect.
0 Kudos
Message 1 of 5
(2,993 Views)
Hello

just wanted to make sure which version of CVI were you using. Becuase only CVI 5.5 and above support multi-threading applications. Are you able to reproduce the problem without having any RS-422 communication in there? Because if you can send a small code snippet, It might give me some more information about the problem

Thanks

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 5
(2,993 Views)
Bilal,

Thanks for taking the time to answer. I am using 5.5. I did some more experimenting today. I found that my communication thread is in a very tight loop when no data is being received. By calling Sleep() in this loop I give the GUI thread a chance to run. This seems to have fixed my problem. I am only passing 1 msec to Sleep() so I am still getting the performance that I need out of my communication thread. Are you aware of any articles that describe how to tune a multi-threaded application so that you get the best compromise of performance vs being a total CPU hog.

Thanks,
Jim
0 Kudos
Message 3 of 5
(2,993 Views)
I dont think I might have something this specific since this would depend on the needs on the application and type of machine you might have. I do have a guide to multi threading applications which just goes thru and describes the various multi threading terms. You might try google also, there bound to be something there. But mostly, it would depend on what you are trying to get out of the application as a whole.

I hope this helps, and Im glad you shared the solution with us.

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 4 of 5
(2,993 Views)
I haven't used multithreading with CVI RS232, but all RS232 functions use 5 sec. delay by default. The function calls are synchronous. Try changing the delay to some lower number like 100msec. when you configure the COM port.
0 Kudos
Message 5 of 5
(2,993 Views)