Results 1 to 8 of 8

Thread: Progress bar problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    78

    Post Progress bar problem

    Hi all i`m trying to use a progress bar while i click a button to start my web cam.

    It needs about 2-3 seconds to display the web cam capture image in my picture box.

    When i use the following code the progress bar starts only when the capture image is displayed in my picture box, it waits those seconds to start.

    What can i do about that problem?

    Code:
     Private Sub TimerProgreesBar_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerProgreesBar.Tick
    
            If ProgressBar1.Value = ProgressBar1.Maximum Then
                ProgressBar1.Visible = False
                TimerProgreesBar.Enabled = False
            Else
                ProgressBar1.Value = ProgressBar1.Value + 10
            End If
        End Sub

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Progress bar problem

    Could you show the complete code please...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: Progress bar problem

    Your thread is blocked with the call to capCreateCaptureWindowA (or however you're doing it) I think you're going to need another thread to display the update information.
    Last edited by 7777; Oct 28th, 2009 at 05:32 PM. Reason: spelling
    Have you tried Google?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    78

    Re: Progress bar problem

    Ok heres how i set up camera

    Code:
     Public Sub startCam(ByVal parentH As Integer)
           
           
            window_handle1 = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, OutputWidth, CShort(OutputHeight), parentH, 0)
    
    
            If setCam() = False Then
                MessageBox.Show("Error setting Up Camera")
            End If
           
        End Sub
    Code:
     Private Function setCam() As Boolean
            'Sets all the camera up
            If SendMessage(window_handle2, WM_CAP_DRIVER_CONNECT, 0, 0) Then
                SendMessage(window_handle2, WM_CAP_SET_PREVIEWRATE, 10, 0)
                SendMessage(window_handle2, WM_CAP_SET_PREVIEW, True, 0)
                isRunning = True
                Return True
            Else
                isRunning = False
                Return False
            End If
        End Function
    On start button click the progress bar should start but it doesn`t it waits to display the image from the web cam and then to fill.

  5. #5
    Junior Member
    Join Date
    Oct 2009
    Location
    Pryor
    Posts
    18

    Re: Progress bar problem

    I don't see where the timer is enabled -- apprently when the button is clicked? You might try putting Application.DoEvents() right after the timer is enabled, and before the call to startcam.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    78

    Re: Progress bar problem

    Why is still doesn`t work? Do i need to include something else?

    Here`s how i activate timerProgreesBar

    Code:
    Private Sub strcam_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strcam.Click
            TimerProgreesBar.Enabled = True
            Application.DoEvents()
                    mycam.startCam(PictureBox1.Handle.ToInt32)
    End sub
    Here`s the timer

    Code:
    Private Sub TimerProgreesBar_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerProgreesBar.Tick
    
            If ProgressBar1.Value = ProgressBar1.Maximum Then
                ProgressBar1.Visible = False
                TimerProgreesBar.Enabled = False
            Else
                ProgressBar1.Value = ProgressBar1.Value + 10
            End If
    
        End Sub
    The progress bar start when the web cam image appears in the picturebox, it stills waits the web cam to connected...

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Progress bar problem

    This works for me... There is a part in the code which I haven't tried and I have indicated that...

    vb Code:
    1. Public Class Form1
    2.     Private Sub btnGo_Click(ByVal sender As System.Object, _
    3.     ByVal e As System.EventArgs) Handles btnGo.Click
    4.         ProgressBar1.Step = 10
    5.         ProgressBar1.Value = 0
    6.         TimerProgreesBar.Enabled = True
    7.         '~~> Haven't tried this part
    8.         mycam.startCam (PictureBox1.Handle.ToInt32)
    9.     End Sub
    10.  
    11.     Private Sub Timer1_Tick(ByVal sender As System.Object, _
    12.     ByVal e As System.EventArgs) Handles Timer1.Tick
    13.         ProgressBar1.PerformStep()
    14.         If ProgressBar1.Value >= ProgressBar1.Maximum Then
    15.             TimerProgreesBar.Enabled = False
    16.         End If
    17.     End Sub
    18. End Class
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: Progress bar problem

    I said before I think your mainUI thread is blocked by the api calls, I could be wrong, through. Perhaps a hack it would probably be an easier solution than figuring out the multithreading, you could just use a animated gif make it visible before the call then set visibility to false after the call completes. Since your progress bar is not really measuring progress only time elapsed, I dont think that it really matters, as long as the user knows its "working"

    google "ajax animated loading gif"
    Have you tried Google?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width