Just create a pseudo connection to the pipe by calling CreateFile. It will unblock the pending ConnectNamedPipe call and you can terminate the thread/application.