public void stop(TaskMonitor monitor) {

		synchronized (this) {
			if (isBusy()) {
				toolTaskMonitor.cancel();
			}
			if (currentTask != null) {
				clearQueuedCommands(currentTask.getDomainObject());
			}
		}

		while (taskThread != null && !monitor.isCancelled()) {
			try {
				Thread.sleep(100);
			}
			catch (InterruptedException e) {
				// try again
			}
		}
	}
Cancel the currently running task and clear all commands that are scheduled to run. Block
until the currently running task ends.

@param monitor a monitor to cancel waiting for the task to finish
Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java