protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            HwndSource source = HwndSource.FromVisual(this) as HwndSource;

            if (null != source)
            {
                SignalViewModel viewModel = this.DataContext as SignalViewModel;
                if (null != viewModel)
                {
                    source.AddHook(viewModel.WindowProc);
                }
            }
        }
Esempio n. 2
0
        private static Mutex CreateMutex(string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            // Allow Everyone to signal the mutex from medium or higher integrity levels.
            MutexSecurity security = new MutexSecurity();
            SignalViewModel.SetSecurity(security);

            // Create the mutex without taking ownership.
            bool created = false;
            Mutex mtx = new Mutex(false, name, out created, security);

            return mtx;
        }
Esempio n. 3
0
        private static EventWaitHandle CreateEvent(string name, bool auto)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            // Allow everyone to signal the event from medium or higher integrity levels.
            EventWaitHandleSecurity security = new EventWaitHandleSecurity();
            SignalViewModel.SetSecurity(security);

            // Create the event without signaling.
            EventResetMode mode = auto ? EventResetMode.AutoReset : EventResetMode.ManualReset;
            bool created = false;
            EventWaitHandle evt = new EventWaitHandle(false, EventResetMode.AutoReset, name, out created, security);

            return evt;
        }
Esempio n. 4
0
        public SignalViewModel()
        {
            this.SetSucceedEventCommand = new RelayCommand(
                param => this.SetSucceedEvent()
                    );

            this.SetFailEventCommand = new RelayCommand(
                param => this.SetFailEvent()
                    );

            // Create the events and mutex to signal later.
            this.succeedEvent = SignalViewModel.CreateEvent(SignalViewModel.SucceedEventName, true);
            this.failEvent = SignalViewModel.CreateEvent(SignalViewModel.FailEventName, true);
            this.waitMutex = SignalViewModel.CreateMutex(SignalViewModel.WaitMutexName);

            this.messages = new ObservableCollection<Message>();

            this.TopMost = true;
            this.PreventShutdown = true;
        }