Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Cancel Long operation from Angular #9605


User avatar
0
andmattia created

Prerequisites

Please answer the following questions before submitting an issue.

  • 7.1.0
  • Angular
  • .net core 2.2 / .net 4.6.1

If issue related with ABP Framework

  • 4.8.1

I try to send a cancellation request from Angular client (use Observable -> unsubscribe) to cancel long Task Operation but API not fire.


    [HttpPost]
        public async Task<GetDataOutputDto> GetDataLongOperation(CustomInputDto input)
        {
            try
            {
                var tokenSource = new CancellationTokenSource(); // _httpContextAccessor.HttpContext.RequestAborted;
                tokenSource.CancelAfter(2500);

                var token = _httpContextAccessor.HttpContext.RequestAborted; //tokenSource.Token;

                var settings = new JsonSerializerSettings
                {
                    Error = (sender, args) => {
                        args.ErrorContext.Handled = true;
                    },
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };


                //... remove for brev
        }

on angular side

                this.subscription = this.loadData(undefined).subscribe(res=>{
                    console.log('data loaded!');
                    this.localData = res.data;
                    //this._rawData = this.localData;
                    this.loadItems();
                    
                });

                setTimeout(() => {
                    console.log('TEST stop long') 
                    this.subscription.unsubscribe();
                }, 2500); 

I test that if I use TaskSource with CancelAfter all code behind work well but from web (client side) I can't fire the cancellation operation


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @andmattia

    Could you upgrade your ABP version to 5.2 or 4.15 and try again ?

    Thanks,

  • User Avatar
    0
    andmattia created

    Hi @ismcagdas

    I found a solution but is not related to a ABP/Zero bug Framework all depends in wich way Angular close / cancel connection.

    In any way I use this solution angular-how-to-cancel-http-calls-on-router-change

    I put it on root.module.ts so now when user change route all connection receive cancellation and it close the flow if is implemented.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks a lot @andmattia :)