Force WCF to use one thread

后端 未结 3 1797
春和景丽
春和景丽 2021-01-14 06:27

I have a console application which uses an external library. The library insists on always being called from the same thread; it locks up otherwise. (I did try runn

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 07:19

    You need to understand SynchronizationContext concept, especially in the context of the WCF. I strongly recommend to read an excellent Programming WCF Services book, where it is described in details. But generally speaking, you can create your own custom SynchronizationContext that creates thread affinity for service calls. There is an example of it in the above mentioned book, but you can read about it also from the same author on MSDN, section Thread Affinity Synchronization Context, which is an example of exactly what you need.

提交回复
热议问题