Multiple calls to same function
-
I asked the question friday, and am gettign to it today. The original question was: I have two controls each of which have loops (we will call loop 1 and loop 2) that call a central function that sends and gets data via serial (we will call Communication function). Only one loop is to run at a time. The problem I am having is when the user requests loop 2 while loop 1 just started. Loop 2 alerts loop 1 to stop, but if loop 1 just started, it will still be calling the communication function until it finishes. I hope this is makeing sense... Meanwhile, loop 2 has started calling communication function as well and I am getting overlap. I cannot simple set a bit and exit the loop at the end. (It is a big program so you will just have to trust me.) Is there a way to cache the values needed to be sent to the communications function? Is there a clean way to exit a loop without it finishing? Should I be focussing on trying to make the two (in reality 10) different loops NEVER call until all other loops are inactive, or should I be trying to make the communication function able to handle multiple calls? Peter V. mentioned Mutex which I tried and is not working. I believe it is not working because each loop is creating a new instance of the Communication function. But is this were true, wouldn't the program treat each instance seperately. Thanks again in advance. ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
-
I asked the question friday, and am gettign to it today. The original question was: I have two controls each of which have loops (we will call loop 1 and loop 2) that call a central function that sends and gets data via serial (we will call Communication function). Only one loop is to run at a time. The problem I am having is when the user requests loop 2 while loop 1 just started. Loop 2 alerts loop 1 to stop, but if loop 1 just started, it will still be calling the communication function until it finishes. I hope this is makeing sense... Meanwhile, loop 2 has started calling communication function as well and I am getting overlap. I cannot simple set a bit and exit the loop at the end. (It is a big program so you will just have to trust me.) Is there a way to cache the values needed to be sent to the communications function? Is there a clean way to exit a loop without it finishing? Should I be focussing on trying to make the two (in reality 10) different loops NEVER call until all other loops are inactive, or should I be trying to make the communication function able to handle multiple calls? Peter V. mentioned Mutex which I tried and is not working. I believe it is not working because each loop is creating a new instance of the Communication function. But is this were true, wouldn't the program treat each instance seperately. Thanks again in advance. ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
I guess making the Communication method static with Mutex applied to it should solve the problem. This will ensure other threads will be blocked until the Communication function exits. As faar as exiting the loop without it finishing, the cleaner method will be pinvoke. Guess it helps. Live Life King Size Alomgir Miah
-
I guess making the Communication method static with Mutex applied to it should solve the problem. This will ensure other threads will be blocked until the Communication function exits. As faar as exiting the loop without it finishing, the cleaner method will be pinvoke. Guess it helps. Live Life King Size Alomgir Miah
Sorry for the delay. I have been woring on the Mutex/ lock idea and almost have it working. I am intrigued however by the PInvoke method. Can you let me know what this is? I have found little information about it, and how it would apply to exitting a loop is escaping me. Thanks, Dwayne ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW