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
Solved

Windows forms question

Posted on 2006-07-10
5
186 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

792 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