Is there anything special I should be doing to gracefully shut down a thread when it has performed a WCF call during its processing?
I seem to be getting a memory leak on my server and I have tracked it down to making a WCF call from my worker threads. I create the threads in a simple way, like this...
var schedule = new Schedule();
var scheduleThread = new Thread(New ParameterizedThreadStart(schedule.Run));
scheduleThread.SetApartmentState(ApartmentState.STA);
scheduleThread.Priority = ThreadPriority.Lowest;
scheduleThread.Start(null);
...and the code for executing my test code that has the issue...
public void Run(object param)
{
var wcf = new TestServer.TestServerClient(...);
wcf.Open();
wcf.Ping();
wcf.Close();
}
...after running it 2000 times I can see using the memory profiler that there are 2000 instances of the following classes...
DispatcherOperationCallback
IntPtr
HwndSubclass
NativeMethods.WndProc
So, is there some cleanup I should be performing relating to using WCF from a thread? Calling GC.Collect() has no impact.
Have you considered using a "using" keyword on every object whose type implements IDisposable?
I hear it's better to use MTA server-side.
I also don't see where you perform thread synchronization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With