Solved

Windows forms question

Posted on 2006-07-10
5
185 Views
Last Modified: 2010-04-23
I have a windows application with one form. The form loads a large amount of data from the database and thus takes a relatively long time to load. I want to add another form (with a progress bar or an image) to a project that will load first and stay while the data form runs on the background, and, when all the data is loaded, I want the progress bar form to close and to display data form with loaded data. What's the best way to do that?
0
Comment
Question by:YZlat
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
plq earned 125 total points
ID: 17072834
Are you sure another form is better ?

What about using multiple threads - one for the form and one for the dataload - and timers to load the data in, and let the form display a progress bar which is later hidden ?
0
 
LVL 35

Author Comment

by:YZlat
ID: 17073101
how can I do this?
0
 
LVL 8

Expert Comment

by:plq
ID: 17073457
Take a look around the System.Threading framework namespace, its all in there.

Basically your form_load sets off a timer on a one time call. The timer creates a new thread and sets it off loading the data, in the meantime your original thread continues to process form events and can update the progress bar. I think you could share form level vars between threads although I'm a bit rusty on that.

Sorry I'm not a very good expert !   Its usually you helping me !  Not much point me trying to assemble an example when you could do it quicker yourself ! :)

0
 
LVL 35

Author Comment

by:YZlat
ID: 17073929
:)

tell me one thing if you know, do I need to close threads after I am done with them?
0
 
LVL 8

Expert Comment

by:plq
ID: 17074079
no, I think .net framework will close all the threads for you when the form ends.

In the meantime you have to suspend the thread once its finished its job. Or I think it can suspend itself, but not tried either..

e.g. System.Threading.Thread.CurrentThread.Suspend

Here's an general example from EE



    Private running As Boolean
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim t As New System.Threading.Thread(AddressOf Me.ThreadedRoutine)
        running = True
        t.Start()
    End Sub

    Private Sub ThreadedRoutine()
        While running
            Debug.WriteLine(DateTime.Now)
            System.Threading.Thread.Sleep(1000)
        Wend
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        running = False
    End Sub


0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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