WCF threading - non-responsive UI

前端 未结 3 1541
天命终不由人
天命终不由人 2020-12-30 14:43

I\'m trying to configure some WCF stuff. Currently, I have a server which allows remote users to download files, and client. In the server, I use a ServiceHost class. I assu

3条回答
  •  抹茶落季
    2020-12-30 14:57

    You should add a ServiceBehaviorAtttribute to the class implementing your service and set its UseSynchronizationContext property to false. This will cause calls to your service to be processed on their own thread.

    Example:

    [ServiceBehavior(UseSynchronizationContext=false)]
    class YourService : IYourService
    {
      // Service Methods
    }
    

    Just remember that if you are going to update any Controls from within your service methods, you must bear in mind the cross-thread programming model of Windows Forms.

提交回复
热议问题