Why would a WCF service hang when using SKCLNET?
Posted by - NA -, Last modified by Tanner O on 30 December 2015 02:59 PM

SKCLNET is implemented as a control and inherits from System.Windows.Forms. A reference to System.Windows.Forms is required for your project to compile. When instantiating the LFile object, the Windows.Forms constructor is going to set the Synchronization Context to the main thread. WCF will default to using that Synchronization Context and can cause the service to hang.

Setting the ServiceBehavior or CallbackBehavior attribute (or similar Behavior attributes) to disable the use of the Synchronization Context will allow separate request/response threads to be created in a thread pool instead of being dispatched to the thread specified in the Synchronization Context, which may be blocked waiting for the previous operating to finish resulting in a deadlock.

For example:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext=false)].

Note that the Instance Mode and ConcurrenyMode are defaults and are not necessarily restricted to these settings.

You can also instantiate the ServiceHost or LFile object in its own thread so that the Synchronization Context does not get set to the main thread the service is running in.