'How to prevent HttpClient.SendAsync Method from sending duplicate data

Is there away to prevent HttpClient.SendAsync method from sending duplicate data.
For context purpose am getting data from one API and posting to another API

I have tried BackgroundWorker to check if async is busy before sending another record without success

                BackgroundWorker bw;
                bw = new BackgroundWorker();
                if (bw.IsBusy != true)
                {
                    bw.DoWork += (obj, ea) => TaskAsync() //containing httpclient.SendAsync;
                    bw.RunWorkerAsync();
                }
                else
                {
                    bw.CancelAsync();
                }

Another solution I tried was TaskAsync().GetAwaiter().GetResult().

Retrieved saved duplicate

This saved record in MSSQL

GL-CLH-8686 | 2022-04-27 21:44:47.907 
GL-CLH-8686 | 2022-04-27 21:44:51.237


Solution 1:[1]

I feel like we need to consider idempotency.

Preventing Duplicate Web Requests To ASP.NET Core

This article uses the uniqueness of database existence values to limit repeated requests.

The easiest way I can cite is to encode the data in the request with the same content in a certain way, assuming that the encoding is named content, then record the current userid, and cache it in redis cache or other caches (databases can also) , for your business, after executing this method, you can release resources or delete this record. Of course, all the information can be completely recorded in the database, but a query operation will be added.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jason