protected SystemWideEventSynchronizer(SynchronousId id, string name, Predicate <object> willHandle,
                                              HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (willHandle == null)
            {
                throw new ArgumentNullException(nameof(willHandle));
            }

            Id            = id;
            WaitHandle    = new EventWaitHandle(false, EventResetMode.ManualReset, name);
            WillHandle    = willHandle;
            m_begun       = begun;
            m_ended       = ended;
            m_allNotified = allNotified;
        }
Beispiel #2
0
        public static ISynchronizable SystemWideEventSet(string name, Predicate <object> willHandle,
                                                         HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
        {
            if (willHandle == null)
            {
                throw new ArgumentNullException(nameof(willHandle));
            }

            return(new SystemWideEventSettable(name, willHandle, begun, ended, allNotified));
        }
Beispiel #3
0
        public static ISynchronizable EventWait(Predicate <object> willHandle,
                                                HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
        {
            if (willHandle == null)
            {
                throw new ArgumentNullException(nameof(willHandle));
            }

            return(new EventWaitable(willHandle, begun, ended, allNotified));
        }
        public EventSynchronizable(Predicate <object> willHandle,
                                   HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
        {
            if (willHandle == null)
            {
                throw new ArgumentNullException(nameof(willHandle));
            }

            m_willHandle  = willHandle;
            m_begun       = begun;
            m_ended       = ended;
            m_allNotified = allNotified;
        }
        public SystemWideEventSynchronizable(string name, Predicate <object> willHandle,
                                             HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (willHandle == null)
            {
                throw new ArgumentNullException(nameof(willHandle));
            }

            m_name        = name;
            m_willHandle  = willHandle;
            m_begun       = begun;
            m_ended       = ended;
            m_allNotified = allNotified;
        }
Beispiel #6
0
        protected EventSynchronizer(SynchronousId id, Predicate <object> willHandle,
                                    HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (willHandle == null)
            {
                throw new ArgumentNullException(nameof(willHandle));
            }

            Id            = id;
            WillHandle    = willHandle;
            m_begun       = begun;
            m_ended       = ended;
            m_allNotified = allNotified;
        }
 protected override SystemWideEventSynchronizer GetSystemWideEventSynchronizer(SynchronousId id, string name, Predicate <object> willHandle,
                                                                               HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
 {
     return(new SystemWideEventSetter(id, name, willHandle, begun, ended, allNotified));
 }
 public SystemWideEventSettable(string name, Predicate <object> willHandle,
                                HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null) :
     base(name, willHandle, begun, ended, allNotified)
 {
 }
 protected abstract SystemWideEventSynchronizer GetSystemWideEventSynchronizer(SynchronousId id, string name, Predicate <object> willHandle,
                                                                               HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null);
Beispiel #10
0
 protected override EventSynchronizer GetEventSynchronizer(SynchronousId id, Predicate <object> willHandle,
                                                           HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null)
 {
     return(new EventWaiter(id, willHandle, begun, ended, allNotified));
 }
Beispiel #11
0
 public EventWaitable(Predicate <object> willHandle,
                      HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null) :
     base(willHandle, begun, ended, allNotified)
 {
 }
Beispiel #12
0
 public EventWaiter(SynchronousId id, Predicate <object> willHandle,
                    HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null) :
     base(id, willHandle, begun, ended, allNotified)
 {
 }
 public SystemWideEventSetter(SynchronousId id, string name, Predicate <object> willHandle,
                              HandledCallback begun = null, HandledCallback ended = null, AllNotifiedCallback allNotified = null) :
     base(id, name, willHandle, begun, ended, allNotified)
 {
 }
Beispiel #14
0
        public void Can_restrain_apps_to_wait_until_ending_process_in_order_of_all_apps()
        {
            // Arrange
            var processes     = new ConcurrentBag <int>();
            var processes_Add = new MarshalByRefAction <int>(i => processes.Add(i));

            void Synchronize(Action <ISynchronizer> action)
            {
                var begun = new HandledCallback((id, obj, opts) =>
                {
                    var threadId = ST::Thread.CurrentThread.ManagedThreadId;
                    Debug.WriteLine($"Begun Id: { id }, Obj: { obj }, Thread: { threadId }");
                });
                var ended = new HandledCallback((id, obj, opts) =>
                {
                    var threadId = ST::Thread.CurrentThread.ManagedThreadId;
                    Debug.WriteLine($"Ended Id: { id }, Obj: { obj }, Thread: { threadId }");
                });
                var curMeth = MethodBase.GetCurrentMethod();
                var waiter1 = Synchronizable.SystemWideEventWait(Key.Get(curMeth, "Foo"), obj => (int)obj == 1, begun, ended);
                var waiter2 = Synchronizable.SystemWideEventWait(Key.Get(curMeth, "Bar"), obj => (int)obj == 2, begun, ended);
                var waiter3 = Synchronizable.SystemWideEventWait(Key.Get(curMeth, "Baz"), obj => (int)obj == 3, begun, ended);

                using (var sync = waiter1.Then(waiter2).Then(waiter3).GetSynchronizer())
                    action(sync);
            }

            // Act
            Synchronize(sync =>
            {
                var task1 = Task.Run(() =>
                                     AppDomain.CurrentDomain.RunAtIsolatedDomain(processes_Add_ =>
                                                                                 Synchronize(sync_ =>
                {
                    sync_.Begin(1).Wait();
                    processes_Add_.Invoke(1);
                    sync_.End(1).Wait();
                }), processes_Add));

                var task2 = Task.Run(() =>
                                     AppDomain.CurrentDomain.RunAtIsolatedDomain(processes_Add_ =>
                                                                                 Synchronize(sync_ =>
                {
                    sync_.Begin(2).Wait();
                    processes_Add_.Invoke(2);
                    sync_.End(2).Wait();
                }), processes_Add));

                var task3 = Task.Run(() =>
                                     AppDomain.CurrentDomain.RunAtIsolatedDomain(processes_Add_ =>
                                                                                 Synchronize(sync_ =>
                {
                    sync_.Begin(3).Wait();
                    processes_Add_.Invoke(3);
                    sync_.End(3).Wait();
                }), processes_Add));

                sync.NotifyAll(false).Wait();


                // Assert
                CollectionAssert.AreEqual(new[] { 1, 2, 3 }, processes);
                Task.WaitAll(task1, task2, task3);
            });
        }