Click here to Skip to main content
15,306,402 members
Home / Discussions / WPF
   

WPF

 
Questionvb.net Pin
RajaMohammed.A20-Sep-19 20:09
MemberRajaMohammed.A20-Sep-19 20:09 
AnswerRe: vb.net Pin
Richard MacCutchan20-Sep-19 21:07
mveRichard MacCutchan20-Sep-19 21:07 
AnswerRe: vb.net Pin
Mycroft Holmes21-Sep-19 12:48
professionalMycroft Holmes21-Sep-19 12:48 
QuestionHow to use DataTrigger to run Storyboard? Pin
Pew_new20-Sep-19 8:00
MemberPew_new20-Sep-19 8:00 
QuestionWPF Pin
RajaMohammed.A19-Sep-19 2:35
MemberRajaMohammed.A19-Sep-19 2:35 
AnswerRe: WPF Pin
Richard Deeming19-Sep-19 2:58
mveRichard Deeming19-Sep-19 2:58 
AnswerRe: WPF Pin
Mycroft Holmes19-Sep-19 13:07
professionalMycroft Holmes19-Sep-19 13:07 
QuestionWindow Not Refreshing Pin
Kevin Marois17-Sep-19 9:03
professionalKevin Marois17-Sep-19 9:03 
I'm working on a custom installation wizard. From it, I'm calling DISM to install IIS and ASP.Net if they're not installed. All the code in the installer class works fine when called from a console app. I'm now trying to put a simple UI on it.

There are 2 steps. Each step raises the event 'CurrentTaskChanged' with text "Installing IIS" or "Installing ASP.Net", and then during installation it raises a ProgressChanged event to send progress to the UI.

The problem is that none of the UI updates happen until the after the entire install process finishes.

Installer Class Code
public static void Install()
{
    InstallIIS();
    InstallASPDotNet();
}

private static void InstallIIS()
{
    InstallFeature("IIS", "/Online /Enable-Feature /FeatureName:IIS-DefaultDocument /All");
}

private static void InstallASPDotNet()
{
    InstallFeature("ASP.Net", "/Online /Enable-Feature /FeatureName:IIS-ASPNET45 /All");
}

private static void InstallFeature(string featureName, string args)
{
    try
    {
        // Raise the task changed event so the UI shows what is installing
        CurrentTaskChanged($"Installing {featureName}");

        string dism = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "dism.exe");
        if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
        {
            dism = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative", "dism.exe");
        }

        var process = new Process();
        var startInfo = new ProcessStartInfo
        {
            UseShellExecute = false,
            CreateNoWindow = false,
            RedirectStandardOutput = true,
            FileName = dism,
            Arguments = args
        };

        process.StartInfo = startInfo;
        process.OutputDataReceived += (sender, e) => HandleDISMOutput(e.Data);
        process.Start();
        process.BeginOutputReadLine();
        process.StartInfo.Verb = "runas";
        process.WaitForExit();
        process.CancelOutputRead();
        process.Close();
    }
    catch (Exception e)
    {
        throw;
    }
}

private static void HandleDISMOutput(object data)
{
    if (data != null)
    {
        var info = data.ToString();

        if (info.Contains("%"))
        {
            // Parse out the percent digits
            info = info.Replace('[', ' ');
            info = info.Replace(']', ' ');
            info = info.Replace('=', ' ');
            info = info.Replace(" ", "");
            info = info.Replace("%", "");

            double.TryParse(info, out double percent);

            // Raise the percent completed event to update the progress bar in the UI
            ProgressUpdated(percent);
        }
    }
}
UI Code
private void InstallExecuted()
{
    RemoteServicesInstaller.CurrentTaskChanged += CurrentTaskChanged;
    RemoteServicesInstaller.ProgressUpdated += ProgressUpdated;
    RemoteServicesInstaller.Install();
}

private void CurrentTaskChanged(string action)
{
    InstallAction = action;
    Debug.Print(action);
}

private void ProgressUpdated(double percent)
{
    InstallPercent = percent;
    Debug.Print(percent.ToString());
}

The two handlers here at the bottom DO get called - the UI just doesn't update during install. I can see the Debug.Print code sending the percent to the debug console. The UI just doesnt refresh.

Anyone have any thougts? Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Window Not Refreshing Pin
Richard Deeming17-Sep-19 9:34
mveRichard Deeming17-Sep-19 9:34 
GeneralRe: Window Not Refreshing Pin
Kevin Marois17-Sep-19 10:03
professionalKevin Marois17-Sep-19 10:03 
GeneralRe: Window Not Refreshing Pin
Richard Deeming18-Sep-19 0:44
mveRichard Deeming18-Sep-19 0:44 
QuestionWPF Pin
RajaMohammed.A9-Sep-19 19:20
MemberRajaMohammed.A9-Sep-19 19:20 
AnswerRe: WPF Pin
Richard MacCutchan9-Sep-19 21:19
mveRichard MacCutchan9-Sep-19 21:19 
QuestionWPF Pin
RajaMohammed.A9-Sep-19 0:25
MemberRajaMohammed.A9-Sep-19 0:25 
AnswerRe: WPF Pin
Gerry Schmitz9-Sep-19 3:09
mveGerry Schmitz9-Sep-19 3:09 
QuestionWPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup18-Aug-19 23:16
MemberJakob Farian Krarup18-Aug-19 23:16 
AnswerRe: WPF application displays differently in Windows 7 and Windows 10 Pin
jimmson21-Aug-19 3:49
Memberjimmson21-Aug-19 3:49 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup25-Aug-19 22:44
MemberJakob Farian Krarup25-Aug-19 22:44 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
jimmson27-Aug-19 21:53
Memberjimmson27-Aug-19 21:53 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup28-Aug-19 1:25
MemberJakob Farian Krarup28-Aug-19 1:25 
AnswerRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Gerry Schmitz28-Aug-19 3:10
mveGerry Schmitz28-Aug-19 3:10 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup28-Aug-19 22:31
MemberJakob Farian Krarup28-Aug-19 22:31 
QuestionWPF and Windows Forms at same time. Pin
michaelbarb15-Aug-19 5:12
Membermichaelbarb15-Aug-19 5:12 
AnswerRe: WPF and Windows Forms at same time. Pin
Pete O'Hanlon15-Aug-19 5:39
mvaPete O'Hanlon15-Aug-19 5:39 
GeneralRe: WPF and Windows Forms at same time. Pin
michaelbarb15-Aug-19 6:15
Membermichaelbarb15-Aug-19 6:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.