1

Topic: Multi-threaded

Good afternoon, In multi-threaded application the code part is closed by the operator lock. private object lockObject = new object ();... public void Method1 () {lock (lockObject) {...}} public void Method2 () {??? if (lockObject) {...}???} As outside of the unit without addressing immediately to it other flow to learn it is blocked or not?

2

Re: Multi-threaded

https://msdn.microsoft.com/en-us/library/4tssbxcw (v=vs.110).aspx var lockObj = new Object (); if (Monitor. TryEnter (lockObj)) {try {//The critical section.} finally {//Ensure that the lock is released. Monitor. Exit (lockObj);}} else {//The lock was not axquired.}

3

Re: Multi-threaded

Hello, CyberRussia, you wrote: CR> In multi-threaded application the code part is closed by the operator lock. CR> private object lockObject = new object (); CR>... CR> public void Method1 () {CR> lock (lockObject) {CR>... CR>} CR>} CR> public void Method2 () {CR>??? if (lockObject) {...}??? CR>} CR> CR> As outside of the unit without addressing immediately to it other flow to learn it is blocked or not? If I correctly understood all: System. Threading. Monitor. IsEntered (lockObject) This method appeared in FW 4.5

4

Re: Multi-threaded

> If I correctly understood all: System. Threading. Monitor. IsEntered (lockObject) Returns true if the current flow holds . How much I understood the HARDWARE, it needs not it. Though, I can be mistaken. A question statement not absolutely clear.

5

Re: Multi-threaded

6

Re: Multi-threaded

Hello, Muxa, you M> Though, I can be mistaken. A question statement not absolutely clear. There are at least two flows. One works with a method which interior is closed by the operator lock from the third, the fourth... Flows. In the first flow there can be a situation when it is necessary to know blocked the second flow the unit of the code or not. If briefly if it is occupied - to wait clearing a little. But! As the blocked code theoretically can hang up strongly for a long time (operation with exterior remote services), and the first cannot long wait, the variant with a waiting semaphore does not approach. Another "but" from the first flow the method with lock is not launched, it is necessary to know about a state of the second flow only.

7

Re: Multi-threaded

Hello, CyberRussia, you wrote: CR> Hello, Muxa, you M>> Though, I can be mistaken. A question statement not absolutely clear. CR> but! As the blocked code theoretically can hang up strongly for a long time (operation with exterior remote services) Here is in itself problem - to work with exterior services from under local . Especially, if exterior services work with something else.