[D7] - Thread

Please discuss general Delphi programming topics here.

[D7] - Thread

Postby dante3d » December 14th, 2010, 9:54 pm

Hello to all ..
I'm Italian and I help my brother for graduation ..
this is my first post .. sorry for my English! :D
I'm doing a program that controls a carriage with stepper motors ..
over carriage is an ultrasound probe that acquires data ..
ok everything works just talking to the I/O ports and synchronizing data (with several "sleep") crashes the GUI .. ](*,)

Then I thought of a "thread" but I put everything in one "thread"? ..
Or only the elements that affect the interaction with the outside world (and thus block the GUI)?!

I would like to highlight the progress of the process (as a rendering in a 3D program) I would like to use a ProgressBar as well as black pixels already processed
Since the threads do not interact with the VCL .. What should I do?
Synchronize the thread with the VCL, or by separate thread?! And how to stop everything if I want to cancel the job?!

Here's my process (very macro) ..
The cycle goes through each pixel of the image (the image is a map of pressure that is a 256-color image obtained from another program and another process) ..

    1. Read the image pixels
    2. Find the color in the DB to find the correct angle of cutting
    3. Position the probe (another long process and if I use a thread I have to go to the angke just found this thread)
    4. wait "X" seconds before reading (pitching vibration) ..
    5. active reading
    6. wait "X" seconds
    7. Turn OFF reading (get the value)
    8. Black the pixel on trial and take forward the process bar ..

I do not care the detail, but a process to figure out which way to go ..

Thank you very much ..
User avatar
dante3d
Member
Member
 
Posts: 3
Joined: December 14th, 2010, 9:24 pm

Re: [D7] - Thread

Postby Kambiz » December 14th, 2010, 11:31 pm

Have you tried the Background Worker Component. I think by this component you can easily move your code in to a separate thread.

Besides the example included in the component's zip file, you can find another example at http://forum.delphiarea.com/viewtopic.php?f=7&t=1435.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: [D7] - Thread

Postby dante3d » December 22nd, 2010, 2:39 pm

Kambiz wrote:Have you tried the Background Worker Component. I think by this component you can easily move your code in to a separate thread.

Besides the example included in the component's zip file, you can find another example at http://forum.delphiarea.com/viewtopic.php?f=7&t=1435.

Thank you for your interest
But I can't terminate the process ..

also using:
Code: Select all
BackGroundWorker.Cancel
BackGroundWorker.WaitFor

the process runs the same until the end
How to kill the process?
User avatar
dante3d
Member
Member
 
Posts: 3
Joined: December 14th, 2010, 9:24 pm

Re: [D7] - Thread

Postby Kambiz » December 22nd, 2010, 8:01 pm

You have to check value of CancellationPending inside OnWork event, and exit the thread when cancel is requested.

Something like this:

Code: Select all
if Worker.CancellationPending then
begin
  Worker.AcceptCancellation;
  Exit;
end;

You'll find more information in the readme file and demos of the component.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: [D7] - Thread

Postby dante3d » December 23rd, 2010, 11:32 am

Ok
thanks
User avatar
dante3d
Member
Member
 
Posts: 3
Joined: December 14th, 2010, 9:24 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron