In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "WCF callback return value instance analysis". In daily operation, I believe many people have doubts about WCF callback return value instance analysis. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "WCF callback return value instance analysis". Next, please follow the editor to study!
When the client implements the WCF callback, if the callback function has a return value, then the return value type can only be a basic type, not an interface type, otherwise the system will not respond to the callback and will not report any error when the service times out.
Because the WCF callback method does not run in the main thread, if the WCF callback method needs to update the interface related to the result of the asynchronous call, such as the lbMessage control in this example, you need to Marshal the callback call to the synchronization context of the current main program interface. We can marshal the call using SynchronizationContext and its SendOrPostCallback delegate:
The service operation is executed asynchronously so that the service will not block the main thread in the process of execution. When the method execution is completed, the client service can be notified of the completion of execution through the corresponding method of AsyncCallback callback. For example:
/ / Invoke it Asynchronously m_service.BeginTransferDocument (mendacal OnTransferComplete had been transfered sucessfully null); / / Do some work; / / callback method void OnTransferCompleted (IAsyncResult result) {Stream stream = m_service.EndTransferDocument (result); result.AsyncWaitHandle.Close (); lbMessage.Text = string.Format ("The file {0} had been transfered sucessfully.", m_doc.FileName) After calling the BeginTransferDocument () method, the main thread will not be blocked and other work can continue. When the service method is executed, the WCF callback method is automatically called to execute the contents of the method. One problem with the above implementation is the operation of the lbMessage control. Because the WCF callback method does not run in the main thread, if the callback method needs to update the interface related to the result of the asynchronous call, such as the lbMessage control in this example, you need to Marshal the callback call to the synchronization context of the current main program interface. We can marshal the call using SynchronizationContext and its SendOrPostCallback delegate:
Public ExplorerClientForm () {InitializeComponent (); m_synchronizationContext = SynchronizationContext.Current;} private SynchronizationContext masked synchronization context;} at this point, the study on "instance analysis of the return value of WCF callback" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.