Get Plugin Definition methods using dependency injection
Create an instance and then use a method on the plugin instance, for example to execute the task, if you have such a method in the plugin class:

$task = \Drupal::service('plugin.manager.task')-&gt;createInstance('my_task');

$task-&gt;execute();