Click here to Skip to main content
12,950,272 members (63,978 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I was reading an article by Juval Lowy. Below section is not clear to me.My Question is : Why callback re requires the ownership of lock? I mean the thread in which the call back is called is waiting for callback to this thread should resume after the callback returns, just like any other method call.

The service may also want to invoke the callback reference passed in or invoke the list of callbacks during the execution of a contract operation. However, such invocations are disallowed because by default the service class is configured for single-threaded access: the service instance is associated with a lock, and only one thread at a time can own the lock and access the service instance. Calling out to the clients during an operation requires blocking the service thread while invoking the callbacks. The problem is that processing the reply message from the client once the callback returns requires ownership of the same lock, and so a deadlock would occur.
To avoid a deadlock, if the single-threaded service instance tries to call back to its clients, Windows Communication Foundation will throw an InvalidOperationException
Posted 9-Sep-12 21:09pm
Updated 10-Sep-12 11:03am
Wes Aday104.2K
Sergey Alexandrovich Kryukov 10-Sep-12 16:35pm
Do you think it's OK to ask a question on an article without a reference?! I think it's not nice at all.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In general case, a callback does not require ownership of a lock, but it can be required if the callback has access to some shared objects. That's it.
For the concrete detail, please address to Juval Lowy. I did not read the article, because you did not give me a reference.

Best regards,
Espen Harlinn 10-Sep-12 18:00pm
Sergey Alexandrovich Kryukov 10-Sep-12 21:27pm
Thank you, Espen.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I assume you are referring to this article What You Need To Know About One-Way Calls, Callbacks, And Events[^]. The real goodie in that article is under the heading "Queued Publishers and Subscribers" which describes how to use WCF with MSMQ, enabling true asychronous operation.

Have a look at WCF / WPF Chat Application[^], it's a better example.

Best regards
Espen Harlinn
Sergey Alexandrovich Kryukov 10-Sep-12 21:29pm
Well, that should provide an overview of what's involved. Considering the lack of information provided by OP, it would be hard to give a better answer. My 5.
Espen Harlinn 11-Sep-12 8:54am
Thank you, Sergey :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100