Alter to use a separated thread to run the apm command.