I have one problem where , there is one task schedular which is running in a interval of 15 minutes where two methods are running. One method is getting some details by calling API. Second method do some operations .
Problem is like when second method is running and busy to download something , it is taking some time to complete . Meanwhile task schedular is running and in that time application is busy in second method and not getting the data by calling first method.
So , how to make two task independly or how to get to knoe previous task schedular specific method is ruuning if running then it will execute as usual and application call the first method as usual.
Loading
Mohammad HussainPosted Jul 27, 2023, 8:16 AM
Here's an outline of how you can approach this:
Asynchronous Programming: Modify both methods to use
asyncandawait. This allows you to perform asynchronous operations without blocking the main thread.Task-based Parallelism: Use the
Taskclass to run the two methods concurrently. You can useTask.Runto execute each method in its own separate task.Cancellation Token: Implement a cancellation mechanism to stop the execution of a task if needed.
Here's an example code snippet to illustrate the concept:
Udit ChauhanPosted Jul 27, 2023, 6:59 AM
Please help on this