Click here to Skip to main content
14,333,747 members

Silverlight / WPF

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder16-Jul-09 3:09
adminChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question PinPopular
Chris Maunder16-Jul-09 3:05
adminChris Maunder16-Jul-09 3:05 
QuestionDataGrid with DataGridTemplateColumns - Cannot create new rows Pin
Mc_Topaz7-Oct-19 23:42
memberMc_Topaz7-Oct-19 23:42 
AnswerRe: DataGrid with DataGridTemplateColumns - Cannot create new rows Pin
Gerry Schmitz8-Oct-19 3:11
mveGerry Schmitz8-Oct-19 3:11 
NewsRe: DataGrid with DataGridTemplateColumns - Cannot create new rows Pin
Mc_Topaz8-Oct-19 3:25
memberMc_Topaz8-Oct-19 3:25 
QuestionWPF Pin
Member 145835423-Oct-19 22:29
memberMember 145835423-Oct-19 22:29 
AnswerRe: WPF Pin
Richard Deeming4-Oct-19 1:59
mveRichard Deeming4-Oct-19 1:59 
AnswerRe: WPF Pin
Richard MacCutchan4-Oct-19 3:22
protectorRichard MacCutchan4-Oct-19 3:22 
AnswerRe: WPF Pin
Gerry Schmitz4-Oct-19 6:32
mveGerry Schmitz4-Oct-19 6:32 
Questionvb.net Pin
Member 1458354220-Sep-19 21:27
memberMember 1458354220-Sep-19 21:27 
AnswerRe: vb.net Pin
Richard MacCutchan21-Sep-19 2:58
protectorRichard MacCutchan21-Sep-19 2:58 
Questionvb.net Pin
Member 1458354220-Sep-19 20:09
memberMember 1458354220-Sep-19 20:09 
AnswerRe: vb.net Pin
Richard MacCutchan20-Sep-19 21:07
protectorRichard MacCutchan20-Sep-19 21:07 
AnswerRe: vb.net Pin
Mycroft Holmes21-Sep-19 12:48
memberMycroft 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
Member 1458354219-Sep-19 2:35
memberMember 1458354219-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
memberMycroft 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
Member 145835429-Sep-19 19:20
memberMember 145835429-Sep-19 19:20 
AnswerRe: WPF Pin
Richard MacCutchan9-Sep-19 21:19
protectorRichard MacCutchan9-Sep-19 21:19 
QuestionWPF Pin
Member 145835429-Sep-19 0:25
memberMember 145835429-Sep-19 0:25 

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.