The following code creates a new thread, acting first as a named pipe client to send parameters, and then as a server to receive the results. After that, it performs a function in another AppDomain, acting as a named pipe, and then, as a client, sends the results back.
public OrderPrice DoAction() { Task<OrderPrice> t = Task<OrderPrice>.Factory.StartNew(NamedPipeClient, parameters); if (domain == null) { domain = AppDomain.CreateDomain(DOMAINNAME); } domain.DoCallBack(AppDomainCallback); return t.Result; } static OrderPrice NamedPipeClient(object parameters) { OrderPrice price = null; using (NamedPipeClientStream stream = new NamedPipeClientStream(PIPE_TO)) { stream.Connect(); SerializeToStream(stream, parameters); } using (NamedPipeServerStream stream = new NamedPipeServerStream(PIPE_BACK)) { stream.WaitForConnection(); price = (OrderPrice)DeserializeFromStream(stream); } return price; } void AppDomainCallback() { OrderPrice price = null; using (NamedPipeServerStream stream = new NamedPipeServerStream(PIPE_TO)) { stream.WaitForConnection(); List<object> parameters = (List<object>)DeserializeFromStream(stream); if (mi != null) price = (OrderPrice)mi.Invoke(action, parameters.ToArray()); } using (NamedPipeClientStream stream = new NamedPipeClientStream(PIPE_BACK)) { stream.Connect(); SerializeToStream(stream, price); } }
On average, code is called once per second, and it works fine for 7 hours. But at some point "system.io.ioexception all pipe instances are busy" is thrown, and after that they no longer reconnect. Looking through here it seems that this may be due to incorrect removal of pipeline objects, but I think that everything is fine, since they are inside using statements. Does anyone know what might be wrong here? The code is in .NET 4.0, running on a Windows 2008 server.
Laurijssen
source share