سؤال

I am working with NamedPipeServerStreams in C# where our clients will be using the Win32 CreateFile and WaitNamedPipe methods to establish connections.

Previously our server was also Win32 and was specifying the 'DefaultTimeOut' as part of the construction of the pipe when calling CreateNamedPipe().

From what I have read/seen, my understanding is that the clients then inherit this timeout value and use it when making calls to WaitNamedPipe.

Microsoft's MSDN documentation for CreateNamedPipe has the following description for the DefaultTimeOut parameter -

*nDefaultTimeOut [in] The default time-out value, in milliseconds, if the WaitNamedPipe function specifies NMPWAIT_USE_DEFAULT_WAIT. Each instance of a named pipe must specify the same value.*

When changing to use the .NET NamedPipeServerStream there seems to be no way of passing this default timeout value into the constructor (or otherwise) and my clients are now regularly timing out on the WaitNamedPipe semaphore, where they were not previously. Without changing all our clients to specify their own timeouts which we'd like to avoid, I can't seem to find a way of doing this in .NET. Surely the .NET NamedPipe code is just wrapping the Win32 API underneath?

هل كانت مفيدة؟

المحلول

If all else fails you could always call CreateNamedPipe via P/Invoke, specifying the default timeout you want just as you did in your Win32 server, and then use the NamedPipeServerStream ctor overload which takes a SafePipeHandle, to wrap it.

The rest of your .NET server code wouldn't need to change.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top