Extra steps when disconnecting a stream using WCF?

Is there anything special I have to do to gracefully close the stream when it makes a WCF call while it is being processed?

It seems that I am getting a memory leak on my server and I tracked it to make a WCF call from my worker threads. I create threads in a simple way, for example ...

var schedule = new Schedule(); var scheduleThread = new Thread(New ParameterizedThreadStart(schedule.Run)); scheduleThread.SetApartmentState(ApartmentState.STA); scheduleThread.Priority = ThreadPriority.Lowest; scheduleThread.Start(null); 

... and code to execute my test code that has a problem ...

 public void Run(object param) { var wcf = new TestServer.TestServerClient(...); wcf.Open(); wcf.Ping(); wcf.Close(); } 

... after starting 2000 times, I see, using the memory profiler, that there are 2000 instances of the following classes ...

 DispatcherOperationCallback IntPtr HwndSubclass NativeMethods.WndProc 

So, is there any kind of cleanup I have to do that involves using WCF from the stream? The call to GC.Collect () is not affected.

+6
source share
1 answer

Have you considered using the "using" keyword for each object whose type implements IDisposable?

I heard that it is better to use the server side of the MTA.

I also do not see where you are performing thread synchronization.

+2
source

Source: https://habr.com/ru/post/909506/


All Articles