RTC Forums

Subscription => Support => Topic started by: bebeantics on March 23, 2018, 10:15:25 AM



Title: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 10:15:25 AM
Hello


I have a small problem with an AniIndicator on Android.
It hangs when I receive a dataset with multiple records.
The reception time is approx. 5-8 seconds.

I can not under any circumstances make the Aniindicator function for the entire duration of the data reception.

on client side i have this request:

  dt.rtcmdsretur.Active:=false;
  dt.rtcmdsretur.Close;
  lwproduseretur.Visible:=false;
  lwproduseretur.Items.Clear;
  text4.Visible:=false;
  aniindicator2.Visible:=true;
  aniindicator2.Enabled:=true;

  with dt.RtcClientModule1 do begin
    data.Clear;

    with data.NewFunction('getretur') do begin

    end;

    try
      call(rtcresult2);
    except
      on e:exception do begin
          showmessage(e.message);
      end;
    end;

  end;

on client side i have this result:
procedure TMainForm.RtcResult2Return(Sender: TRtcConnection; Data,
  Result: TRtcValue);
begin
  if not Sender.inMainThread then
    Sender.Sync(RtcResult2Return, Data, Result)
  else
    begin
        ...
        ...
        else if (Data.isType=rtc_Function) and (Data.asFunction.FunctionName='getretur') then begin

                 if Result.isType = rtc_Dataset then begin

                      dt.rtcmdsretur.asDataSet := Result.asDataSet;
                      Result.Extract;

                      dt.rtcMdsretur.Active := True;
                      lwproduseretur.Visible:=true;

                 end
                 else if result.isType=rtc_exception then
                      showmessage(result.asException);

                 aniindicator2.Enabled:=false;
                 aniindicator2.Visible:=false;
                 text4.Visible:=true;
        end;

    end;
end;

Can someone help me?

[UPDATE]  or somewhere needs to be tested if we have finished receiving the answer ....


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 23, 2018, 10:48:04 AM
If you set AutoConnect:=TRUE and MultiThreaded:=TRUE on the TRtcHttpClient component responsible for handling your requests and you leave AutoSyncEvents:=FALSE (default value) on components linked to that TRtcHttpClient component (for example on the TRtcClientModule component), then all the RTC code responsible for sending and/or receiving data will be executed from background threads (the Main Thread will NOT be used for sending or receiving data), allowing other components to use the Main Thread without interruption while data is being sent and/or received.

NOTE: Setting AutoSyncEvents:=TRUE on any RTC component would result in all events assigned to that component to be synchronized with the Main Thread (the event is posted to the Main Thread and executed there, while the Background Thread waits for the event to finish). This is similar to calling the Sender.Sync() method from inside all events triggered by the RTC component and would therefor execute all events assigned to that component from the Main Thread (instead of background threads), even if you set MultiThreaded:=TRUE on the TRtcHttpClient component.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 11:08:50 AM
I change in the rtcclientmodule.autosyncevents:=false;

the problem not solved.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 11:10:09 AM
deleted the
if not Sender.inMainThread then
    Sender.Sync(RtcResult2Return, Data, Result)
  else
    begin

from the firs lines of onresulevent to

the problem not solved


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 23, 2018, 11:12:38 AM
1. How are the other properties on TRtcHttpClient and TRtcClientModule set?

2. Is the Main Thread busy or idle during data transfer? For example, if you place a TMemo or TEdit field on the Main Form, can you use it normally while data is being sent and received, or does the Main Form become unresponsive after using the call method?


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 11:21:58 AM
HttpClient. MultiThreaded:=TRUE
httpclient.AutoConnect:=TRUE
httpclient.useproxy:=true

for clientmodule
autorepost:=2
autosyncevent:=false
autosession:=false
hyperthreading:=false
autologin:=false;


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 11:35:45 AM
2. Is the Main Thread busy or idle during data transfer? For example, if you place a TMemo or TEdit field on the Main Form, can you use it normally while data is being sent and received, or does the Main Form become unresponsive after using the call method?

The main thread is not unresponsive. I have some buttons, tabcontrols, etc and working under the datareceive event panding


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 23, 2018, 11:40:26 AM
If other things that require access to the Main Thread are working while data is being sent and/or received, then your problem with "AniIndicator" (or any other component you might be using) is unrelated to the RTC SDK.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 11:46:52 AM
If i delete all rtc requests from on click event that call the function from the server side, everything working fine.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 23, 2018, 11:47:41 AM
I assume that you are using the latest RTC SDK version. If you are using an older RTC SDK version, then I recommend you to download the latest RTC SDK version and update your code if needed (see Updates log files for details).

RTC SDK has been refactored in v9 and some units have been removed in the process. Make sure to unpack the RTC SDK into a new folder when updating and remove eventual paths to old RTC SDK versions, or you could end up mixing units from different RTC SDK versions.

After the update, make sure you are NOT using the "rtcFMX.GUI" or similar units in your Project.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 11:54:37 AM
i have v8.14 installed on D10.2.3 version

Updating from a RTC SDK version released before v9.00? Read this topic (v9.00).
Updating from a RTC SDK version released before v8.14? Also read this topic (v8.14).

I use de first or the second topic ?


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 23, 2018, 12:01:22 PM
You only need to read update logs for versions released AFTER the version you are currently using. So ... if you have already updated to RTC SDK v8.14 before, assuming that you have read the updates log for that version, you only need to read update logs for versions released after that. In your case, this includes all update logs for RTC SDK v8.15 and later versions, but the absolute MUST READ is RTC SDK v9.0 - which includes important notes about refactoring.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 12:15:18 PM
where i can read about the properties/functions/procedure in what units are?

i have a Write_File undeclared identifier now, but I do not want to bother you with these issues


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 23, 2018, 12:25:10 PM
Because most utility classes and functions were moved from other units to the "rtcSystem" unit, adding the "rtcSystem" unit to the "uses" list should fix most compile errors about "undeclared" RTC functions or classes. You can read more about this in the RTC SDK v9.0 updates log.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 12:46:58 PM

the initial problem still persists


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 23, 2018, 01:46:28 PM
If you are using the latest RTC SDK version (which also means that you are NOT using the "rtcFMX.GUI" or similar units somewhere in your Project), I fail to see how RTC code running in background threads could negatively affect completely unrelated visual components, unless these visual components require a large portion of the CPU and do NOT work correctly when there are background threads running and using the CPU.

Anyway ... I still claim that the problem is unrelated to the RTC SDK, but since your problem is with the "TAniIndicator" component and you are using RTC components with background threads, you might want to "google" to see if anyone else has problems with that component when using threads and running code in the background.


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: bebeantics on March 23, 2018, 08:55:39 PM
THIS IS JUST A WORKAROUND

My solution was the following

tha rtcclientmodule is in a datamodule.

procedure Tdt.RtcClientModule1ResponseDone(Sender: TRtcConnection);
begin
if mainform.AniIndicator2.Visible then
    if not mainform.Text4.Visible then begin
        MainForm.AniIndicator2.Visible:=false;
        mainform.AniIndicator2.Enabled:=false;
        mainform.Text4.Visible:=true;
    end;
end;

on the rtcresult site, i delete everything was relative to aniindicator and remaining just this.
....
else if (Data.isType=rtc_Function) and (Data.asFunction.FunctionName='getretur') then begin

                 if Result.isType = rtc_Dataset then begin

                      dt.rtcmdsretur.asDataSet := Result.asDataSet;
                      Result.Extract;

                      dt.rtcMdsretur.Active := True;
                      lwproduseretur.Visible:=true;
                 end
                 else if result.isType=rtc_exception then
                      showmessage(result.asException);
end;

Somehow Result.Extract invokes an event of ending the reception of information, although the records have not yet been received (or transferred to rtcmdsretur)


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 24, 2018, 11:41:55 AM
The "Result.Extract" method does NOT invoke any events. The "Extract" method simply removes a pointer to the object contained within "Result", so the object (asDataSet - in your case) won't be destroyed when the "Result" object is destroyed. And since the pointer to the object contained within "Result" was removed, any data previously stored in the "Result" object can also NOT be accessed using the "Result" object after calling "Extract". But ... judging by your code, this was intended, so I don't see any problems there.

I hope you didn't completely remove your code for synchronizing your events with the Main Thread. Any code accessing any visual components and/or controls HAS TO be called from the Main Thread, or it won't work correctly. Since you are using the TRtcHttpClient component with "MultiThreaded:=TRUE", any events you assign to that TRtcHttpClient component or any other components linked to it (like the TRtcClientModule component you are using to call remote functions) will be executed from background threads, unless you use the "Sender.Sync" method to synchronize your event with the Main Thread (as you did before), or set "AutoSyncEvents:=TRUE" for all RTC components with events accessing the GUI (visual components or controls).


Title: Re: AniIndicator freeze on DataResult as Dataset
Post by: D.Tkalcec (RTC) on March 24, 2018, 12:05:59 PM
Based on your "workaround", I think I understand now what your actual problem was.

You've placed multiple remote function calls into the queue and have enabled the "TAniIndicator" component before placing each remote function call into the queue, but have disabled the "TAniIndicator" immediately after receiving the first result from the Server, ignoring the fact that other remote calls could still be waiting in the queue with more results to come later.

Because of that, it probably appeared to you as if the "TAniIndicator" component "froze", while in fact it was working until the 1st result arrived, after which you've disabled it, so that it was no longer working when other remote calls were being sent and/or their results received.

Since you are using RTC components in Multi-Threded and Asynchronous event-driven mode, you can place any number of requests and/or remote function calls into the queue instantly, but they will all be sent out (later) serialized, one after the other, with their results arriving in the same way. First the result from the 1st remote call, then from the 2nd and so on.

If you want to show an animation on the Client when data is being sent and/or received, you can use the "OnBeginRequest" event to enable your animation and then use "OnResponse*" events to disable that animation (there are multiple events there, depending on what happened with the response). Because of the asynchronous nature of RTC components and the way you are using them, this would actually be the most correct way to achieve what you wanted.