Jump to content

Long Server Side Process


dionel1969

Recommended Posts

Hello:

 

I have a process that is responsible for "Sale Process" of various points of sale. This procedure takes time depending on the amount of POS that were working in a day and depending on the sale of each of these POS. Then, when the sale is small no problem, but when is large before processing finished application gives an error of "Time Out".

 

The question is: How I can do to have a process feedback directly from the server in the window showing the results and avoid the time-out error?

 

I put a timer, but does not start at the time indicated.

 

procedure TProcessForm.ProcessSale;
begin
 try
  fProcessStart := Now;

  tmrProcess.Enable := True;

  ProcessSaleInternal;

 finally
  tmrProcess.Enable := False;
 end
end;

procedure TProcessForm.tmrProcessTimer(Sender: TObject);
begin
 pnlProcessing.Caption := 'Procesando Venta. Tiempo de Procesamiento: ' + IntToStr(MillisecondsBetween(Now, fProcessStart));
end;

Link to comment
Share on other sites

Hello,

 

I put a timer, but does not start at the time indicated.

Timer triggers repetitively, it starts when enabled, not for time indicated, if so let know..

 

Now about TimeOut.., See UniGui Demos SessionTimeout

Try

begin
 UniMainModule.AllowTerminate:=False;
 ProcessForm.ProcessSale();
 UniMainModule.AllowTerminate:=True;
 showmsg;
end;

procedure TUniMainModule.UniGUIMainModuleSessionTimeout(ASession: TObject; var ExtendTimeOut: Integer);
begin
 if not AllowTerminate then
 begin
   ExtendTimeOut:=15000;  // extend session for another 15 seconds
 end;
end;

Link to comment
Share on other sites

You must implement a thread and run the lengthy operation in that thread. Then inform the client using a UniTimer about the progress status. There was a example regarding this somewhere in samples forum.

Please look at http://forums.unigui.com/index.php?/topic/1479-progressbar-multithreading-demo/

It contains a simple example showing how to do this with UniGUI.

Link to comment
Share on other sites

Hello,

 

I put a timer, but does not start at the time indicated.

Timer triggers repetitively, it starts when enabled, not for time indicated, if so let know..

 

Of course, I do understand this, but I wanted to say that the Timer only become to Enable when the Form Show at init, not later. It est, I want to set Enable to True before Start Sale Process and then when the process come to finish set Enable to False. So, Timer will trigger Timer Events and I will use theses events for refreshing "Sale Process Status and Position".

 

This is not working:

 

procedure TUniMainModule.UniGUIMainModuleSessionTimeout(ASession: TObject; var ExtendTimeOut: Integer);
begin
 if not AllowTerminate then
 begin
   ExtendTimeOut:=15000;  // extend session for another 15 seconds
 end;
end;

 

The Event is not triggering by MainModule.

Thank you again.

Link to comment
Share on other sites

I also observed the same, that timer doesn't triggers as long as the main thread is busy in processing some ProcessSaleInternal procedure.

also, UniGUIMainModuleSessionTimeout doesn't execure as the main thread is busy.

 

This lengthy operation have to be processed in a thread, as Farshad have already suggested.

 

Regards

Link to comment
Share on other sites

I also observed the same, that timer doesn't triggers as long as the main thread is busy in processing some ProcessSaleInternal procedure.

also, UniGUIMainModuleSessionTimeout doesn't execure as the main thread is busy.

 

This lengthy operation have to be processed in a thread, as Farshad have already suggested.

 

Regards

 

Ok, Thanks a lot for your help. I'm now converting the Process, because it come "as is" from the same application but a versiion that is running in Windows. For a few POSes and a few tickets it works well, the problem come when there are a lot of tickets. So, it is obvious that I have to convert the process to run it in a separate thread and then I need to use timer to get feed back from server side.

 

Thanks again.

 

Dionel

Link to comment
Share on other sites

  • Administrators

I also observed the same, that timer doesn't triggers as long as the main thread is busy in processing some ProcessSaleInternal procedure.

also, UniGUIMainModuleSessionTimeout doesn't execure as the main thread is busy.

 

This lengthy operation have to be processed in a thread, as Farshad have already suggested.

 

Regards

 

Like all other events Timer event executes cooperatively and only executes when owner session is not busy running other events.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...