Jump to content

Help Required With Threads


andyhill

Recommended Posts

I have the following code that is supposed to update a progressbar while emailing (pbWaiting updating works):-

 

...

 

  if Assigned(job) then begin
    if not (job.Finished or job.Terminated) then begin
      job.Terminate;
    end;
    job.Free;
  end;
  //
  job:= TJobThread.Create;
  job.FreeOnTerminate:= False;
  pbWaiting.Position:= 4;
  job.Execute; ON EXECUTION WE NEVER PROGRESS TO THE NEXT LINE (SendMail) ?
  //
  UniMainModule.SendMail(LoginForm.edtEmail.Text, LoginForm.edtPassword.Text, edtFirstName.Text, edtLastName.Text, edtPhone.Text);
  //
  job.JobCounter:= 100;
  job.Terminate;
 
 
Please advise - thanks in advance
 
Link to comment
Share on other sites

procedure TJobThread.Execute;

begin

  JobCounter:= 6;

  while not Terminated and (JobCounter < 100) do begin

    Inc(JobCounter);

    if JobCounter > 99 then begin

      JobCounter:= 6;

    end;

    UniSession.AddJS(Format('NewAccountRequestForm.pbWaiting.updateProgress(%d/%d, ''Running...'', true);', [JobCounter, 100]));

    UniSession.Synchronize;

    Sleep(500);

  end;

end;
Link to comment
Share on other sites

  • Administrators

 

procedure TJobThread.Execute;
begin
  JobCounter:= 6;
  while not Terminated and (JobCounter
    Inc(JobCounter);
    if JobCounter > 99 then begin
      JobCounter:= 6;
    end;
    UniSession.AddJS(Format('NewAccountRequestForm.pbWaiting.updateProgress(%d/%d, ''Running...'', true);', [JobCounter, 100]));
    UniSession.Synchronize;
    Sleep(500);
  end;
end;

 

 

A big NO!

 

You can't use uniGUI methods inside a thread.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...