Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. App "NOT RESPONDING" on opening some other window

App "NOT RESPONDING" on opening some other window

Scheduled Pinned Locked Moved Windows Forms
helpcsharpdatabasesql-server
8 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    All Time Programming
    wrote on last edited by
    #1

    Hi, I have devloped an desktop application in Vb.NET somthing of importing/updating data with SQL server. App works fine as expected, but when the databse process is going on & if I open any other window then the application shows "Not Responding" on top, part of app window that has components turns white, text/components r not visible or doesn't show update in TextBox BUT the application is running in back & updating the data lying on server. Due to this I can't know the status of the Import + "Not Responding" on title bar gives the msg that something has gone wrong & an error has occured (but actually no error has occured). Can anyone tell why does this happen & how to overcome this problem. Any help/guidance is highly appreciated.

    Thanks & Regards,

    D 1 Reply Last reply
    0
    • A All Time Programming

      Hi, I have devloped an desktop application in Vb.NET somthing of importing/updating data with SQL server. App works fine as expected, but when the databse process is going on & if I open any other window then the application shows "Not Responding" on top, part of app window that has components turns white, text/components r not visible or doesn't show update in TextBox BUT the application is running in back & updating the data lying on server. Due to this I can't know the status of the Import + "Not Responding" on title bar gives the msg that something has gone wrong & an error has occured (but actually no error has occured). Can anyone tell why does this happen & how to overcome this problem. Any help/guidance is highly appreciated.

      Thanks & Regards,

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This usually happens because you have a long running process executing on the UI thread, namely, your database processing. You have to move that processing to a background thread in order to keep the UI responsive and painting itself (the white window goes away).

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This usually happens because you have a long running process executing on the UI thread, namely, your database processing. You have to move that processing to a background thread in order to keep the UI responsive and painting itself (the white window goes away).

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        A Offline
        A Offline
        All Time Programming
        wrote on last edited by
        #3

        Thanks Dave, but the UI is related to DB processing. On updating DB, msg is shown on Textbox, so textbox updating is related to db processing. Then yet, in that case will the threading be useful ? My code is such : sub StartProcessing() ' Perform Main Main_Processing() ' Perform Other Other_Processing() ' Item Processing Item_Processing() return End sub sub Main_Processing() .... .... cmd.Execute("Update .......") statusTxt.AppendText("Updated document # ...") end sub How & where do I add Thread.Run....

        Thanks & Regards,

        D 1 Reply Last reply
        0
        • A All Time Programming

          Thanks Dave, but the UI is related to DB processing. On updating DB, msg is shown on Textbox, so textbox updating is related to db processing. Then yet, in that case will the threading be useful ? My code is such : sub StartProcessing() ' Perform Main Main_Processing() ' Perform Other Other_Processing() ' Item Processing Item_Processing() return End sub sub Main_Processing() .... .... cmd.Execute("Update .......") statusTxt.AppendText("Updated document # ...") end sub How & where do I add Thread.Run....

          Thanks & Regards,

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          StartProcessing would launch the thread that executes everything else. Any UI updates (TextBox messages) would have to be Invoke a method on the UI thread that updates the control. Read this article[^]

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          A 1 Reply Last reply
          0
          • D Dave Kreskowiak

            StartProcessing would launch the thread that executes everything else. Any UI updates (TextBox messages) would have to be Invoke a method on the UI thread that updates the control. Read this article[^]

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            A Offline
            A Offline
            All Time Programming
            wrote on last edited by
            #5

            Hi Dave, Learning from the article you provided, I did sme homework. I think I am going somewhere wrong, Can you please check it. Actually have never worked with Threading with .NEt, have worked with Java. Private Delegate Sub ControlStringConsumer(ByVal control As Control, ByVal text As String) ' defines a delegate type ' SetTextData to update text of TextBox (statusTxt) Private Sub SetTextData(ByVal control As Control, ByVal text As String) If (control.InvokeRequired) Then control.Invoke(New ControlStringConsumer(AddressOf SetTextData), New Object() {control, text}) Else control.Text = text End If End Sub ' Update Imported Private Sub updateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateBtn.Click If (ValidateInputs()) Then importAdd = False ' ADDED THREADING EXECUTION FOR Start_Processing Dim myThreadDelegate As New ThreadStart(AddressOf Start_Processing) Dim myThread As New Thread(myThreadDelegate) myThread.Start() 'Start_Processing() End If End Sub Private Sub Start_Processing() 'statusTxt.AppendText(vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf) dim s as string = vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf SetTextData(statusTxt, s) ......... Endif I feel the Threading part is correct - maybe can remove ThreadStart & straight away give AddOf to Thread(). But feel their is somethign wrong with SetTextData. Here I want to AppendText & not only set some new value to it. If this is the right way to do, then everytime I will have to call it as :- dim s as string = statusTxt.Text + vbcrlf + " MY NEW TExT" + vbcrlf SetTextData(statusTxt, s) OR is it so that I should overwrite AppendText instead of SetText & SetText should be used & not SetTextData ???? What do u say, am I going anywher wrong. Don't know why, but this time feeling scared to run without confirmity. Maybe b'coz using Threads. I know how unsafe threads can be if not operated properly.

            Thanks & Regards,

            L 1 Reply Last reply
            0
            • A All Time Programming

              Hi Dave, Learning from the article you provided, I did sme homework. I think I am going somewhere wrong, Can you please check it. Actually have never worked with Threading with .NEt, have worked with Java. Private Delegate Sub ControlStringConsumer(ByVal control As Control, ByVal text As String) ' defines a delegate type ' SetTextData to update text of TextBox (statusTxt) Private Sub SetTextData(ByVal control As Control, ByVal text As String) If (control.InvokeRequired) Then control.Invoke(New ControlStringConsumer(AddressOf SetTextData), New Object() {control, text}) Else control.Text = text End If End Sub ' Update Imported Private Sub updateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateBtn.Click If (ValidateInputs()) Then importAdd = False ' ADDED THREADING EXECUTION FOR Start_Processing Dim myThreadDelegate As New ThreadStart(AddressOf Start_Processing) Dim myThread As New Thread(myThreadDelegate) myThread.Start() 'Start_Processing() End If End Sub Private Sub Start_Processing() 'statusTxt.AppendText(vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf) dim s as string = vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf SetTextData(statusTxt, s) ......... Endif I feel the Threading part is correct - maybe can remove ThreadStart & straight away give AddOf to Thread(). But feel their is somethign wrong with SetTextData. Here I want to AppendText & not only set some new value to it. If this is the right way to do, then everytime I will have to call it as :- dim s as string = statusTxt.Text + vbcrlf + " MY NEW TExT" + vbcrlf SetTextData(statusTxt, s) OR is it so that I should overwrite AppendText instead of SetText & SetText should be used & not SetTextData ???? What do u say, am I going anywher wrong. Don't know why, but this time feeling scared to run without confirmity. Maybe b'coz using Threads. I know how unsafe threads can be if not operated properly.

              Thanks & Regards,

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Your code looks basically OK, assuming SetTextData() is not directly manipulating a GUI Control. Similar to (from the article):

              public void SetText(Control control, string text) {
              if (control.InvokeRequired) {
              control.Invoke(new ControlStringConsumer(SetText), new object[]{control, text}); // invoking itself
              } else {
              control.Text=text; // the "functional part", executing only on the main thread
              }
              }

              you should do:

              public void AppendText(TextBox control, string text) {
              if (control.InvokeRequired) {
              control.Invoke(new ControlStringConsumer(AppendText), new object[]{control, text}); // invoking itself
              } else {
              control.AppendText(text); // the "functional part", executing only on the main thread
              }
              }

              :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              A 1 Reply Last reply
              0
              • L Luc Pattyn

                Your code looks basically OK, assuming SetTextData() is not directly manipulating a GUI Control. Similar to (from the article):

                public void SetText(Control control, string text) {
                if (control.InvokeRequired) {
                control.Invoke(new ControlStringConsumer(SetText), new object[]{control, text}); // invoking itself
                } else {
                control.Text=text; // the "functional part", executing only on the main thread
                }
                }

                you should do:

                public void AppendText(TextBox control, string text) {
                if (control.InvokeRequired) {
                control.Invoke(new ControlStringConsumer(AppendText), new object[]{control, text}); // invoking itself
                } else {
                control.AppendText(text); // the "functional part", executing only on the main thread
                }
                }

                :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                A Offline
                A Offline
                All Time Programming
                wrote on last edited by
                #7

                Thanks Dave & Luc. But am getting error : ERROR: Cross-thread operation not valid: Control 'statusTxt' accessed from a thread other than the thread it was created on Luc, I added AppendText as you mentioned ad removed SetTextData which was wrong. Same way added Thread, and my code is as below :

                Private Delegate Sub ControlStringConsumer(ByVal control As Control, ByVal text As String)    ' defines a delegate type
                
                Private Sub importNewBtn\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles importNewBtn.Click
                    If (ValidateInputs()) Then
                        'Start\_Processing()
                        Dim myThreadDel As New ThreadStart(AddressOf Start\_Processing)
                        Dim myThread As New Thread(myThreadDel)
                        myThread.Start()
                    End If
                End Sub
                
                Public Sub AppendText(ByVal control As TextBox, ByVal text As String)
                    If (control.InvokeRequired) Then
                       ' invoking itself SHOWS WARNING - IMPLICIT CONVERSION FROM CRONTROL TO TEXTBOX
                        control.Invoke(New ControlStringConsumer(AddressOf AppendText), New Object() {control, text})  
                    Else
                        control.AppendText(text)      ' the "functional part", executing only on the main thread    
                    End If
                End Sub
                
                Private Sub Start\_Processing()
                    EnableComponents(False)
                    statusTxt.Clear()  ' ---- GENERATING ERROR
                
                    statusTxt.AppendText(vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf)
                    ' Load all required basic Data
                    If (setUp() = False) Then
                        Return
                    End If
                
                    statusTxt.AppendText(vbCrLf + "Generating....." + vbCrLf)
                    GenerateQueries()
                    statusTxt.AppendText(vbCrLf + "Data Set Up Completed - " + Now.ToString + vbCrLf)
                
                    ' ADD ALL RECORDS OF main TO REGISTER
                    statusTxt.AppendText(vbCrLf + "Processing Main transactions ..... " + Now.ToString + vbCrLf)
                    MainProcessing()
                
                    ' Update UFV records to Register
                    statusTxt.AppendText(vbCrLf + "Processing UFV transactions ..... " + Now.ToString + vbCrLf)
                    UFVProcessing()
                
                    ' Update Item records to Register
                    statusTxt.AppendText(vbCrLf + "Processing Item transactions ..... " + Now.ToString + vbCrLf)
                    ItemProcessing()
                
                    ' Update Tax records to register
                    statusTxt.AppendText(vbCrLf + "Processing Tax transactions ..... " + Now.ToString + vbCrLf)
                    TaxProcessing()
                
                    ' Update Qty, Rate records to Register
                
                L 1 Reply Last reply
                0
                • A All Time Programming

                  Thanks Dave & Luc. But am getting error : ERROR: Cross-thread operation not valid: Control 'statusTxt' accessed from a thread other than the thread it was created on Luc, I added AppendText as you mentioned ad removed SetTextData which was wrong. Same way added Thread, and my code is as below :

                  Private Delegate Sub ControlStringConsumer(ByVal control As Control, ByVal text As String)    ' defines a delegate type
                  
                  Private Sub importNewBtn\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles importNewBtn.Click
                      If (ValidateInputs()) Then
                          'Start\_Processing()
                          Dim myThreadDel As New ThreadStart(AddressOf Start\_Processing)
                          Dim myThread As New Thread(myThreadDel)
                          myThread.Start()
                      End If
                  End Sub
                  
                  Public Sub AppendText(ByVal control As TextBox, ByVal text As String)
                      If (control.InvokeRequired) Then
                         ' invoking itself SHOWS WARNING - IMPLICIT CONVERSION FROM CRONTROL TO TEXTBOX
                          control.Invoke(New ControlStringConsumer(AddressOf AppendText), New Object() {control, text})  
                      Else
                          control.AppendText(text)      ' the "functional part", executing only on the main thread    
                      End If
                  End Sub
                  
                  Private Sub Start\_Processing()
                      EnableComponents(False)
                      statusTxt.Clear()  ' ---- GENERATING ERROR
                  
                      statusTxt.AppendText(vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf)
                      ' Load all required basic Data
                      If (setUp() = False) Then
                          Return
                      End If
                  
                      statusTxt.AppendText(vbCrLf + "Generating....." + vbCrLf)
                      GenerateQueries()
                      statusTxt.AppendText(vbCrLf + "Data Set Up Completed - " + Now.ToString + vbCrLf)
                  
                      ' ADD ALL RECORDS OF main TO REGISTER
                      statusTxt.AppendText(vbCrLf + "Processing Main transactions ..... " + Now.ToString + vbCrLf)
                      MainProcessing()
                  
                      ' Update UFV records to Register
                      statusTxt.AppendText(vbCrLf + "Processing UFV transactions ..... " + Now.ToString + vbCrLf)
                      UFVProcessing()
                  
                      ' Update Item records to Register
                      statusTxt.AppendText(vbCrLf + "Processing Item transactions ..... " + Now.ToString + vbCrLf)
                      ItemProcessing()
                  
                      ' Update Tax records to register
                      statusTxt.AppendText(vbCrLf + "Processing Tax transactions ..... " + Now.ToString + vbCrLf)
                      TaxProcessing()
                  
                      ' Update Qty, Rate records to Register
                  
                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  1. So you added my Sub AppendText, however you are not calling it anywhere. All statusTxt.AppendText(someString) have to be replaced by AppendText(statusTxt, someString), I thought that was obvious to anyone who read my article. 2. statusTxt.Clear() is also forbidden, it needs similar treatment. 3. the warning is my fault, you have to define (and use) new delegates, so make an almost clone of ControlStringConsumer. I suggest you read the article again until you understand what should and shouldn't be done with Controls. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  modified on Monday, September 27, 2010 2:13 PM

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups