Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use WCF threads

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use WCF threads, I hope you have something to gain after reading this article, let's discuss it together!

Although many people are skeptical about WCF threads, his security continues to improve year after year. It is possible to keep the WCF thread running properly, but only if you have a deep understanding of what a WCF thread is and how it works.

For these operations, any creation of a new thread to execute is equivalent. However, in some cases, some operations can only be performed under a fixed thread. For example, in a GUI application, access to a control needs to be performed under the thread that created the control

Or we set some Context information in a fixed thread through TLS (Thread Local Storage) for specific operations, and we call the operation and the dependency of a fixed thread thread Thread Affinity.

In the case of WCF, whether you host a service or specify a callback when calling Service, by default, the operations of service and callback are automatically associated with the current SynchonizationContext (if any).

That is, if our service is host under the Windows Form application, then the operation of the service will be performed under the UI thread; similarly, how we call the duplex service and define the callback in a Windows Forms UI thread, then the final execution of the callback will be in the UI thread.

The control of WCF thread affinity can be set through the UseSynchronizationContext property of ServiceBehavior or CallbackBehavior, which defaults to true, which is the reason why WCF has thread affinity by default.

Now let's implement our second set of scenarios: so that Callback execution does not have to be bound to UI threads. To do this, we just need to add what kind of CallbackBehavior attribute.

Namespace Artech.ThreadAffinity.Clients {[CallbackBehavior (UseSynchronizationContext = false)] public class CalculateCallback: ICalculateCallback {public static TextBox ResultPanel; # region ICalculateCallback Members public void DisplayResult (double result) {ResultPanel.Text = result.ToString ();} # endregion}} after reading this article, I believe you have some understanding of "how WCF threads are used". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report