I'm a novice in Multithreading
, i have a procedure that goes through a series of operations using indy (login to a site and download files and ...), sometimes when a site is not responsive or it takes too long, no exception occurs even with idHttp.connectTimeout
and idHttp.readTimeout
set to a specific amount or sometimes it does occur but not at the time i have specified !!, which is why i prefer to check the task and see if for example an ITask
is running for 30 sec, it must be terminated !, i tried using itask.cancel
but it only cancels if something is in queue and doesn't terminate a task that is already running, what is the solution to my problem ?
just so you know what is happening in my program :
originally my program creates classes based on a list of profiles and starts a process of login and download, i want to terminate any startDownloadProcess
that takes more than 30 sec
here is a code example :
// this is what i used to do
for I := 0 to mProfileList.count - 1 do
begin
myClass := TMyClass.create(mProfileList[i]);
//sometimes this takes a very very long time and i don't want that.
myClass.startDownloadProcess;
end;
// here is what i have in mind
for I := 0 to mProfileList.count - 1 do
begin
mITaskArray[i] := TTask.run(procedure
begin
myClass := TMyClass.create(mProfileList[i]);
myClass.startDownloadProcess;
end);
end;
What i need :
i want each task to depend on the previous one (a queue) and wait until the previous one completes, and if a task takes more than 30 second, it terminates and the queue continues.
now i know there might be a lot of things wrong with that code but that is why i'm here, i'm a bit lost about how to proceed or if what i'm doing is correct at all !