How to run a batch on a condition

D365.
I have a runBaseBatch class. On a condition I should run it interactively or as a batch (without showing a dialog)
I’m doing :

MyRunBaseBatchClass myClass = new MyRunBaseBatchClass()
myClass.parm1(); …myClass.parmN();
myClass.saveLast();
myClass.batchInfo().ParmBatcheExecute(runInBatch)
if(runInBatch)
myClass.doBatch()
else
myClass.runOperation();

It seems like it’s working, but I’m not sure if it is correct or I am missing something?

Thanks a lot in advance