Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows forms question

Posted on 2006-07-10
5
Medium Priority
?
190 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 375 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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