Solved replacing this line: CreateThread(null, 0, &_fun, &fun, 0, null); to this code: task!({CreateThread(null, 0, &_fun, &fun, 0, null);}).executeInNewThread();