none
Problem when using Taskbar Manager and Microsoft.WindowsAPICodePack

    Question

  • I have made a simple application as described here: http://www.dreamincode.net/forums/topic/163162-show-progress-bar-progress-on-windows-taskbar-win7-only/

    No problems if I only use one form but if I add a second form to the project identical to the first, the code

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
            ProgressBar1.Value = TrackBar1.Value * 10
            TaskbarManager.Instance.SetProgressValue(TrackBar1.Value * 10, 100)
    End Sub

    does not always work. This seems to be a random bug. If I start the app, do nothing else but show the second form, the code works. However, if I close the second form and then reopen it, there's a 50% chance the code won't perform. Once it fails to perform, the only solution is the close the app and start again.

    Exactly the same thing happens when I call SetOverlayIcon from the second form. It works the first time the second form is opened. It sometimes works when the second form is closed and  reopened but not always!

    Has anyone else experienced this? I would be grateful for any enlightenment.

    Wednesday, September 26, 2012 11:11 AM

Answers

  • Since when we reopen the second form, the TaskbarManager.Instance owner handle is not changed. And the TaskbarManager.Instance still references to the previous closed form handle. The TaskbarManager uses singletion pattern, and does not recreate the instance when we reopen the second form.

    Try to show your second form as the child form on the first form, then the TaskbarManager instance and the progress can always show in the first form:

        Dim frm As New Form2
        frm.Show(Me)

    Or you could let the TaskbarManager.Instance create for the first form before showing the second form, then the progress can always show in the first form:

        TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress)
        Dim frm As New Form2
        TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal)
        frm.Show()


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by RobboD Thursday, September 27, 2012 1:45 PM
    Thursday, September 27, 2012 4:03 AM
    Moderator

All replies

  • Since when we reopen the second form, the TaskbarManager.Instance owner handle is not changed. And the TaskbarManager.Instance still references to the previous closed form handle. The TaskbarManager uses singletion pattern, and does not recreate the instance when we reopen the second form.

    Try to show your second form as the child form on the first form, then the TaskbarManager instance and the progress can always show in the first form:

        Dim frm As New Form2
        frm.Show(Me)

    Or you could let the TaskbarManager.Instance create for the first form before showing the second form, then the progress can always show in the first form:

        TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress)
        Dim frm As New Form2
        TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal)
        frm.Show()


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by RobboD Thursday, September 27, 2012 1:45 PM
    Thursday, September 27, 2012 4:03 AM
    Moderator
  • Many thanks for your explanations.
    • Marked as answer by RobboD Thursday, September 27, 2012 1:45 PM
    • Unmarked as answer by RobboD Thursday, September 27, 2012 1:46 PM
    Thursday, September 27, 2012 7:22 AM
  • can you reset the owner of the .Instance to a new window? my main form doesnt have a taskbar icon and all the other forms will open and close. So after the first form that used the .instance and closed, can i open a new form with a new instance? Or have 2 windows with 2 instances?
    Monday, March 10, 2014 6:07 AM