Solved

VB.NET form freezes when running big commands

Posted on 2004-08-13
4
665 Views
Last Modified: 2012-05-05
I have a search command that searches thru folders and subdirectories and I cannot move the form till it is done. How can I make it not freeze the window ?
0
Comment
Question by:Vartana
  • 3
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11796986
You have two basic options:

1) Place Application.DoEvents() in your For...Next loop (or in your recursive subroutine) to allow your application to process messages such as moving the form or mouse clicks, etc.

2) Place the search routine in another thread.

Idle_Mind
0
 
LVL 1

Author Comment

by:Vartana
ID: 11797028
2) Place the search routine in another thread.

Example please ?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 11797096
This would make the label go from 1 to 100000 while still allowing the UI to be responsive.  If you called threadedRoutine directly the UI would lock up until the loop completed.

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim t As New System.Threading.Thread(AddressOf Me.threadedRoutine)
        t.Start()
    End Sub

    Private Sub threadedRoutine()
        Dim i As Integer

        For i = 1 To 100000
            Label1.Text = i
        Next
    End Sub
End Class

If you don't want to use another thread then you could change threadedRoutine() to include Application.DoEvents() like this:

    Private Sub threadedRoutine()
        Dim i As Integer

        For i = 1 To 100000
            Label1.Text = i
            Application.DoEvents()
        Next
    End Sub

Regards,

Idle_Mind
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11797118
As a side note...using the Thread method, the Label continues to update as the form is moved.  Using the Application.DoEvents() method, the Label is not updated again until the form has stopped being dragged.

Idle_Mind
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Red error squiggly on vb.net 7 27
update textboxes with Streamreader 21 42
LINQ - C# to VB convertion 12 46
Web Form VB.Net  import CSV 4 21
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now