LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I stop a process in one thread from within another thread

Hi, 

I am new to multithreading so I'm hoping my question has an obvious answer. I am running a GUI, one of whose commands is "Download file". This command takes a long time to execute, so I want to be able to interrupt its execution and go back to my starting point. I am heartened by the following comment, gleaned from Wikipedia:

http://en.wikipedia.org/wiki/Thread_%28computer_science%29

states:

A common use of threads is having one thread paying attention to the graphical user interface, while others do a long calculation in the background. As a result, the application more readily responds to user's interaction.

What this suggests to me is the following:
  1. Run the GUI in one thread
  2. Run "Download file" in a second thread
  3. Have a control in the GUI which terminates the second thread.
That is as far as I've gotten. I've tried a few things, but my understanding of the multithreading functions is too limited to produce the result I want. Any help would be appreciated.

Regards,

Charles E. Gray
0 Kudos
Message 1 of 4
(3,442 Views)

I would suggest you to use PostDeferredCalltoThread () function.

You must define a deferred callback to stop the download and call it with PostDefferredCallToThread from the main thread. Inside the function that executes the download you must insert a GetUserEvents () or ProcessSystemEvents () to let the deferred function to execute.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,434 Views)
Roberto,

Thank you for the prompt response. I'll work on that today,

Regards,

Charles E. Gray
0 Kudos
Message 3 of 4
(3,425 Views)

A simple way of doing this is simply to set a global variable TRUE when the user opts to abort the download. Your secondary thread which is doing the download continuously checks the state of this flag while it is executing and if it finds it is set, it takes whatever steps are necessary to perform a controlled abort, before finally unsettting the flag and then terminating.

Jamie

0 Kudos
Message 4 of 4
(3,381 Views)