DO LOOP String.IsNullOrEmpty Threading VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SyGC
    New Member
    • Feb 2008
    • 17

    DO LOOP String.IsNullOrEmpty Threading VB.NET

    Hey All,

    im trying to simply display an image depending on whether a text box has been populated or not. To do this im using the String.IsNullOr Empty(My String) approach.

    Becuase the image will change depending on the textbox field state the String.IsNullOr Empty(My String) is placed in a DO LOOP and Thread

    Code:
        Private Sub backgroundprocess()
    
            Dim Results As String = Results_TextBox2.Text
    
    
            Do
                If String.IsNullOrEmpty(Results) = True Then
    
                    Gif = True
                Else
                    Gif = False
                End If
    
            Loop
            Application.DoEvents()
            Thread.Sleep(1000)
    
        End Sub
    The Boolean return of Gif then determines the visible property of the image(picturebo x)

    Code:
    Private Sub Button1_Click
    
            If GIf = True Then
                PictureBox1.Visible = True
            ElseIf GIf = False Then
                PictureBox1.Visible = False
            End If
    This is all being used as a 'cheat' (Due to time constraints) to display a gif image during any times when a delay in results is expected (Like a progress bar)

    The text field being populated is returning the results of a trace route.
    IF the text field is empty (Waiting for the process to finish and System.IO.Strea mReader to read to end) then the gif will be displayed. Once the text field has been populated with the results (System.IO.Stre amWriter writing to it) the gif image will not be displayed anymore.

    Any thoughts? If you want to see the whole code let me know :P

    Thanks in advance as always,

    Sy
  • vanc
    Recognized Expert New Member
    • Mar 2007
    • 211

    #2
    I'm not quite sure about your idea but I can see your dummy code is on the right track. Though, there are some points that I don't understand in your code. The first thing is Do ... Loop, is it should be Do While () .. Loop, otherwise this code will become infinite loop and the main thread has no chance to run!!!
    To revise your idea, your code should be like
    <dummy code>
    Do While (targetTextBox. Text != "")
    Thread.Sleep(10 00); //this is not main thread
    Loop
    DisplayGif(); //this is function to display your image
    </dummy code>

    If you don't understand how to do it in details. Feel free to ask. Cheers.

    Comment

    • SyGC
      New Member
      • Feb 2008
      • 17

      #3
      Originally posted by vanc
      I'm not quite sure about your idea but I can see your dummy code is on the right track. Though, there are some points that I don't understand in your code. The first thing is Do ... Loop, is it should be Do While () .. Loop, otherwise this code will become infinite loop and the main thread has no chance to run!!!
      To revise your idea, your code should be like
      <dummy code>
      Do While (targetTextBox. Text != "")
      Thread.Sleep(10 00); //this is not main thread
      Loop
      DisplayGif(); //this is function to display your image
      </dummy code>

      If you don't understand how to do it in details. Feel free to ask. Cheers.
      Hi Vanc

      Yea doing the DO While LOOP makes much more sense. The issue hasnt been resolved though.

      Ive put in the button click event the following;

      Code:
              
      
              Dim GifThread As Thread
              GifThread = New Thread(AddressOf Me.backgroundprocess)
              GifThread.Start()
      
              GifPicBox.Visible = True
      
              If GIf = True Then
      
                  GifPicBox.Visible = False
      
              End If
      and This as the background process;

      Code:
              Dim Results As String = L2T_Results.Text
      
      
              Do While L2T_Results.Text = ""
      
                  GIf = True
      
              Loop
              Thread.Sleep(1000)
      GIf is declared as a global variable as Boolean ' Dim GIf As Boolean'

      So as i see it. On button click picture box visibility = true and is shown...however it isnt getting the boolean result back to set visibility to 'false' when the text field is till empty (Both 'String.IsEmpty orNull and .text= "" have been used)

      Im sure im being a plank with this...full code would be .....

      Code:
         Dim GIf As Boolean
      
          Private Sub backgroundprocess()
      
              Dim Results As String = L2T_Results.Text
      
      
              'Do While String.IsNullOrEmpty(Results)
      
              Do While L2T_Results.Text = ""
      
                  GIf = True
      
              Loop
              Thread.Sleep(1000)
      
          End Sub
      
          Private Sub ping_PButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ping_PButton.Click
      
              Dim GifThread As Thread
              GifThread = New Thread(AddressOf Me.backgroundprocess)
              GifThread.Start()
      
              GifPicBox.Visible = True
      
              If GIf = True Then
      
                  GifPicBox.Visible = True
      
              End If
      
              code....
      
      End Sub
      ]#

      Thanks again

      Sy
      Last edited by SyGC; Apr 5 '08, 11:58 AM. Reason: add thanks

      Comment

      Working...