You are developing a Windows Communication Foundation (WCF) service that is hosted by a Windows Forms Application.
The ServiceHost instance is created in the Form Constructor.
You need to ensure that the service is not blocked while the UI thread is busy. What should you do?
A.
Decorate the service implementation class with the following line of code
[ServiceBehavior(UseSyncronizationContext = false)]
B.
Decorate the service implementation class with the following line of code
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
C.
Call the Invoke method of the form and supply a delegate.
D.
Call the BeginInvoke method of the form and supply a delegate.
Explanation:
ServiceBehaviorAttribute.UseSynchronizationContext Property
(http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.usesynchronizationcontext.aspx)ServiceBehaviorAttribute.UseSynchronizationContext Property
Gets or sets a value that specifies whether to use the current synchronization context to choose the thread of execution.Use this property to provide the user interface thread affinity that some applications require.
For example, a Windows Forms application may be registered as a singleton service object.
In this case, all calls into the service must run on the Windows Forms thread.
The default case, in which UseSynchronizationContext is set to true, synchronizes all calls to
the service to run on the thread captured from the System.Threading.SynchronizationContext.Writing Smart Clients by Using Windows Communication Foundation
(http://msdn.microsoft.com/en-us/library/cc294424.aspx)
A