public ApplicationRuntime(bool closeAfterCheck)
        {
            UiThreadHelper.InitializeWithCurrentDispatcher();

            mCloseAfterCheck = closeAfterCheck;

            mUpdateManager = new WindowsUpdateManager(_OnSearchFinished);
            mWmiWatcher    = new WmiWatcher(SearchForUpdates);
            mVersionHelper = new VersionHelper();
            mTimer         = new DispatcherTimer();

            mTrayIcon      = new SystemTrayIcon(this);
            mMenuViewModel = new MenuViewModel(this, mVersionHelper);
        }
示例#2
0
        public void Start()
        {
            if (mIsRunning && mStopRequested == false)
            {
                return;
            }

            mStopRequested = false;

            Task.Factory.StartNew(() =>
            {
                try
                {
                    mWatcher = _CreateEventWatcher();
                    ManagementBaseObject result = null;

                    while (mStopRequested == false)
                    {
                        try
                        {
                            result = mWatcher.WaitForNextEvent();
                            break;
                        }
                        catch (ManagementException)
                        {
                            // timeout of WaitForNextEvent()
                            // -> wait again
                        }
                    }

                    mWatcher.Stop();
                    mIsRunning = false;

                    if (result != null && mStopRequested == false)
                    {
                        UiThreadHelper.BeginInvokeInUiThread(mOnStateChanged);
                    }
                }
                finally
                {
                    if (mWatcher != null)
                    {
                        mWatcher.Dispose();
                    }
                }
            }, CancellationToken.None, TaskCreationOptions.LongRunning, System.Threading.Tasks.TaskScheduler.Default);
        }