Shaitan00 Posted August 30, 2009 Posted August 30, 2009 I have a class (NamedPipeManager) which has a thread (PipeThread) that waits for a NamedPipe connection using (ConnectNamedPipe) and then reads (ReadFile) - these are blocking calls (not-overlapped) - however there comes a point when I want to unblock them - for example when the calling class tries to stop the NamedPipeManager... How can I interupt it? Using Thread.abort? Thread.interrupt? Is there a proper way to handle this? Refer to the code below which illustrates my current situation main() { NamedPipeManager np = new NamedPipeManager(); ... do stuff ... ... do stuff ... np.Stop(); // at this point I want to stop waiting on a connection } class NamedPipeManager { private Thread PipeThread; public NamedPipeManager { PipeThread = new Thread(new ThreadStart(ManagePipes)); PipeThread.IsBackground = true; PipeThread.Name = "NamedPipe Manager"; PipeThread.Start(); } private void ManagePipes() { handle = CreateNamedPipe(..., PIPE_WAIT, ...); ConnectNamedPipe(handle, null); // this is the BLOCKING call waiting for client connection ReadFile(....); // this is the BLOCKING call to readfile after a connection has been established } public void Stop() { /// This is where I need to do my magic /// But somehow I need to stop PipeThread PipeThread.abort(); //?? my gut tells me this is bad } }; [/Code] So, in function Stop() - how would I gracefully unblock the call to ConnectNamedPipe(...) or ReadFile(...)? Any help would be appreciated. Thanks, Quote
Administrators PlausiblyDamp Posted August 31, 2009 Administrators Posted August 31, 2009 I am assuming that CreateNamedPipe is just the Windows API being called - if so you should just use CloseHandle to close the pipe. http://msdn.microsoft.com/en-us/library/aa365166%28VS.85%29.aspx can be used to disconnect an already connect pipe though. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.