Solved

Windows forms question

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

18 Experts available now in Live!

Get 1:1 Help Now