Solved

Windows forms question

Posted on 2006-07-10
5
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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