class MYPROJECT_API AbandonAsyncTask
{
public:
friend class FAsyncTask<AbandonAsyncTask>;
void DoWork()
{
.......
}
bool CanAbandon()
{
return true;
}
}
//I create an instance
auto Task=new FAsyncTask();
I want to know how to Abandon this task ? I tried to use “Task->Cancel()”,but it didn’t work.
I find a function “Abandon()” in AsyncWork.h,but This function is not public.
Can someone tell me how to do?
It’s been a number of months, but in case anyone else needs the answer, you just create Abandon() on your templated class, have it do whatever you need when abandoning.
In the OP’s case, you actually use auto* Task= new FAsyncTask< AbandonAsyncTask>();
Here’s the source comment for Abandon():
* Always called from the thread pool. Called if the task is removed from queue before it has started which might happen at exit. If the user job can abandon, we do that, otherwise we force the work to be done now (doing nothing would not be safe).*
It will check if CanAbandon() is true, else it will call DoWork()
I don’t use it myself, I manage it manually through an array where I can tell remaining tasks to cancel. It’s based of a different type of AsyncTask, maybe TAsyncTaskGraph, but I don’t remember.
I would try to find the queue it’s added to and see if you can remove it yourself or something along those lines.