You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve the code for ShowAutoClosingTaskDialog in TaskDialogDemo Form1 (vb & c#)
In the example of ShowAutoClosingTaskDialog it only works well with 5 seconds or less, to make that example easier to understand or if more than 5 seconds of waiting are used, a couple of code changes would have to be made in both Form1.cs as in Form1.vb.
Issue:
The sample code fails when the result of remainingTenthSeconds * 2 is greater than 100.
The sample code fails when a value of more than 5 seconds is used, since when assigning the value of remainingTenthSeconds = seconds * 10, the maximum value of the progress bar turns out to be less than the resulting value of: remainingTenthSeconds * 2.
The new update code should be something like this:
For C#:
// Set then maximum value for the ProgressBar
var maximum = remainingTenthSeconds * 2;
page.ProgressBar.Maximum = maximum;
// Create a WinForms timer that raises the Tick event every tenth second.
using (var timer = new Timer()
{
Enabled = true,
Interval = 100
})
{
timer.Tick += (s, e) =>
{
remainingTenthSeconds--;
if (remainingTenthSeconds > 0)
{
// Update the remaining time and progress bar.
page.Text = string.Format(textFormat, (remainingTenthSeconds + 9) / 10);
page.ProgressBar.Value = maximum - remainingTenthSeconds * 2;
}
else
{
// Stop the timer and click the "Reconnect" button - this will
// close the dialog.
timer.Enabled = false;
reconnectButton.PerformClick();
}
};
TaskDialogButton result = TaskDialog.ShowDialog(this, page);
if (result == reconnectButton)
Console.WriteLine("Reconnecting.");
else
Console.WriteLine("Not reconnecting.");
}
For VB:
' Set then maximum value for the ProgressBar
Dim maximum = remainingTenthSeconds * 2
page.ProgressBar.Maximum = maximum
' Create a WinForms timer that raises the Tick event every tenth second.
Using timer = New Windows.Forms.Timer() With {
.Enabled = True,
.Interval = 100
}
AddHandler timer.Tick,
Sub(s, e)
remainingTenthSeconds -= 1
If remainingTenthSeconds > 0 Then
' Update the remaining time and progress bar.
page.Text = String.Format(textFormat, (remainingTenthSeconds + 9) \ 10)
page.ProgressBar.Value = maximum - remainingTenthSeconds * 2
Else
' Stop the timer and click the "Reconnect" button - this will
' close the dialog.
timer.Enabled = False
reconnectButton.PerformClick()
End If
End Sub
Dim result As TaskDialogButton = TaskDialog.ShowDialog(Me, page)
If result = reconnectButton Then
Console.WriteLine("Reconnecting.")
Else
Console.WriteLine("Not reconnecting.")
End If
End Using
Hope this helps.
Guillermo
Issue metadata
Issue type: sample-update
The text was updated successfully, but these errors were encountered:
elGuille-info
changed the title
Improved the code for ShowAutoClosingTaskDialog in TaskDialogDemo Form1 (vb & c#)
Improve the code for ShowAutoClosingTaskDialog in TaskDialogDemo Form1 (vb & c#)
Apr 7, 2022
Improve the code for ShowAutoClosingTaskDialog in TaskDialogDemo Form1 (vb & c#)
In the example of ShowAutoClosingTaskDialog it only works well with 5 seconds or less, to make that example easier to understand or if more than 5 seconds of waiting are used, a couple of code changes would have to be made in both Form1.cs as in Form1.vb.
Issue:
The sample code fails when the result of remainingTenthSeconds * 2 is greater than 100.
The sample code fails when a value of more than 5 seconds is used, since when assigning the value of remainingTenthSeconds = seconds * 10, the maximum value of the progress bar turns out to be less than the resulting value of: remainingTenthSeconds * 2.
The actual code is:
For C#
For VB:
Solution:
The new update code should be something like this:
For C#:
For VB:
Hope this helps.
Guillermo
Issue metadata
The text was updated successfully, but these errors were encountered: