System.Threading.Monitor.Pulse C# (CSharp) Method

Pulse() public static method

public static Pulse ( object obj ) : void
obj object
return void
		public static void Pulse(object obj) {
			if(obj==null) {
				throw new ArgumentNullException("obj");
			}
			if(Monitor_test_synchronised(obj)==false) {
				throw new SynchronizationLockException("Object is not synchronized");
			}

			Monitor_pulse(obj);
		}

Usage Example

Esempio n. 1
0
        public void TestComplexMonitor()
        {
            this.Test(async() =>
            {
                object syncObject = new object();
                bool waiting      = false;
                List <string> log = new List <string>();
                Task t1           = Task.Run(() =>
                {
                    Monitor.Enter(syncObject);
                    log.Add("waiting");
                    waiting = true;
                    Monitor.Wait(syncObject);
                    log.Add("received pulse");
                    Monitor.Exit(syncObject);
                });

                Task t2 = Task.Run(async() =>
                {
                    while (!waiting)
                    {
                        await Task.Delay(1);
                    }

                    Monitor.Enter(syncObject);
                    Monitor.Pulse(syncObject);
                    log.Add("pulsed");
                    Monitor.Exit(syncObject);
                });

                await Task.WhenAll(t1, t2);

                string expected = "waiting, pulsed, received pulse";
                string actual   = string.Join(", ", log);
                Specification.Assert(expected == actual, "ControlledMonitor out of order, '{0}' instead of '{1}'", actual, expected);
            },
                      this.GetConfiguration());
        }
All Usage Examples Of System.Threading.Monitor::Pulse