Beispiel #1
0
        private async void stopService_Click(object sender, RoutedEventArgs e)
        {
            LogUpdateInto("stopping service...");

            bool result = await WinServiceUtils.StopServiceAsync("wuauserv", 5000);

            if (result)
            {
                LogUpdateInto("success!");
            }
            else
            {
                LogUpdateInto("fail!");
            }
        }
        async Task Cleanup()
        {
            //unregister all events
            //todo is this really necessary: considering that
            //this reference lives here in the Page only
            if (winUpdateManager != null)
            {
                winUpdateManager.CheckCompleted        -= WinUpdateManager_CheckCompleted;
                winUpdateManager.DownloadCompleted     -= WinUpdateManager_DownloadCompleted;
                winUpdateManager.InstallationCompleted -= WinUpdateManager_InstallationCompleted;
                winUpdateManager.ProgressChanged       -= WinUpdateManager_ProgressChanged;

                //in case there is still somehting going on at the moment
                //todo can this cause problems?
                //winUpdateManager.AbortAll();

                winUpdateManager.CleanUp();

                winUpdateManager = null;
            }
            await WinServiceUtils.StopServiceAsync(WinUpdatesManager.WUA_SERVICE_NAME, 60000).ConfigureAwait(false);

            WinServiceUtils.TrySetStartupType(WinUpdatesManager.WUA_SERVICE_NAME, false);
        }