0

I have a problem using WCF ChannelFactory in multi threading environment. When I call the a method from the ChannelFactory, I keep geting timeout on my calls.

private static ChannelFactory<Foo> factory = null;
private static object lockObj = new object();

... in my thread method:

Foo obj
lock(lockObj)
{
    if(factory == null)
    {
        factory = new ChannelFactory<Foo>(basicBinding, New EndpointAddress(New Uri(u)));
    }
    obj = factory.CreateChannel();
}

obj.doSomething();
obj.close()

... When the code execute the obj.doSomething(), I get a timeout exception and I don't understand why. And worst, some times, the call pass witought problems and I ged expected results.

I also noted that there are only 2 call made when the program execute.

  • You want to multithread to create channelfactory, this seems to be the case of this timeout,. You can see [this case](https://stackoverflow.com/questions/10420973/timeoutexception-in-wcf-after-multiple-calls) for reference. – Jiayao Oct 20 '22 at 06:18
  • So, if I understand well, it's because I have too many channel open at the same time? though I don't understand why it would accept only 2 connection open at a time and why it work whit the class Threading.Thread but not with the class Threading.BackgroundWorker – randomProg Oct 21 '22 at 11:41
  • Open a channelfactory at the same time and see if the problem persists. If it doesn't exist, it's because of this problem. – Jiayao Oct 25 '22 at 08:55

1 Answers1

0

Ok, I do not understand why, but it seem that the backgroundWorker that we use to manage the threads cap the number of connection to 2. The Thread class though does not block the connections