473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Im trying to use backgroundWorker to show a progressBar before app loaded:

The splash screen is running for 3-5 seconds then close.

Then after it i want to show a progressBar on the screen from the time the splash screen have been closed untill the application is loaded.

This is the code in the constructor of Form1 of the splash screen and the backgroundWorker:


Expand|Select|Wrap|Line Numbers
  1. while (splash_flag == true)
  2.             {
  3.                 splash.Show();
  4.                 Thread.Sleep(3000);
  5.                 splash_flag = false;
  6.             }
  7.             if (splash_flag == false)
  8.             {
  9.  
  10.                 splash.Close();
  11.             }
  12.             myProgressBar2 = new ProgressBar();
  13.             {
  14.                 myProgressBar2.Maximum = 100;
  15.                 backgroundWorker1.WorkerReportsProgress = true;
  16.                 backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
  17.                 backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
  18.                 backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
  19.             };
  20.             backgroundWorker1.RunWorkerAsync(myProgressBar2);
  21.  

Now here is the functions of the backgroundWorker on the bottom of Form1 code:

Firs the backgroundWorker1_DoWork:


Expand|Select|Wrap|Line Numbers
  1. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  2.          {
  3.              for (int i = 0; i < 100; i++)
  4.              {
  5.  
  6.                  Thread.Sleep(100);
  7.  
  8.                  backgroundWorker1.ReportProgress(i); 
  9.  
  10.              }
  11.  
  12.          }
  13.  
Then the other two functions:


Expand|Select|Wrap|Line Numbers
  1. private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) //call back method
  2.          {
  3.  
  4.              myProgressBar2.Value = e.ProgressPercentage;
  5.  
  6.          }
  7.          private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) //call back method
  8.          {
  9.  
  10.              myProgressBar2.Value = progressBar1.Maximum;
  11.  
  12.          }
  13.  
But nothing happen. When i run the application i see the splash screen thats ok after it nothing waiting for the application to load.

I want that while the form1 making connection tests to the internet it will show me how long it takes to the application to load.

This is the code of the backgroundWorker with the internet connection tests this time.

I want that after the splash screen when its making internet connection tests so it will show me in this time how much time left to load the application:


Expand|Select|Wrap|Line Numbers
  1. myProgressBar2 = new ProgressBar();
  2.             {
  3.                 myProgressBar2.Maximum = 100;
  4.                 backgroundWorker1.WorkerReportsProgress = true;
  5.                 backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
  6.                 backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
  7.                 backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
  8.             };
  9.             backgroundWorker1.RunWorkerAsync(myProgressBar2);
  10.  
  11.  
  12.             if (fdt.http_test() == true)
  13.             {
  14.                 Client.DownloadFile(satellite_address, temp_dir + satellite_file_name);
  15.                 label6.Enabled = true;
  16.                 label6.Visible = true;
  17.                 label6.Text = "internet connection is active";
  18.             }
  19.             else
  20.             {
  21.                 Logger.Write("Connection to the internet has failed");
  22.                 button1.Enabled = true;
  23.                 timer1.Enabled = false;
  24.                 label6.Enabled = true;
  25.                 label6.Visible = true;
  26.             }
  27.             if (fdt.satellite_test() == true)
  28.             {
  29.                 Client.DownloadFile(satellite_address, temp_dir + satellite_file_name);
  30.                 label6.Enabled = true;
  31.                 label6.Visible = true;
  32.                 label6.Text = "internet connection is active";
  33.             }
  34.             else
  35.             {
  36.                 Logger.Write("Connection to the internet has failed");
  37.                 button1.Enabled = true;
  38.                 timer5.Enabled = false;
  39.                 label6.Enabled = true;
  40.                 label6.Visible = true;
  41.             }
  42.             if (fdt.http_test() == true)
  43.             {
  44.                 Client.DownloadFile(remote_image_on_server, temp_dir + temp_file);
  45.                 label6.Enabled = true;
  46.                 label6.Visible = true;
  47.                 label6.Text = "internet connection is active";
  48.             }
  49.             else
  50.             {
  51.                 Logger.Write("Connection to the internet has failed");
  52.                 button1.Enabled = true;
  53.                 timer1.Enabled = false;
  54.                 label6.Enabled = true;
  55.                 label6.Visible = true;
  56.             }
  57.  

Thanks.
Oct 3 '10 #1
3 4134
cloud255
427 Expert 256MB
You have not assigned your progress bar to the collection of controls of the form object.

I have added 2 lines of code (23 and 24). That should solve your problem.

The progress bar control will not render until you give it a parent and call she show method. You could have used the designer to add the progress bar to the form, that would have generated the missing code for you in the Designer.cs file.

You might also want to have a look at your general design before going live with this project.

HTH

Expand|Select|Wrap|Line Numbers
  1.    1. while (splash_flag == true)
  2.    2.             {
  3.    3.                 splash.Show();
  4.    4.                 Thread.Sleep(3000);
  5.    5.                 splash_flag = false;
  6.    6.             }
  7.    7.             if (splash_flag == false)
  8.    8.             {
  9.    9.  
  10.   10.                 splash.Close();
  11.   11.             }
  12.   12.             myProgressBar2 = new ProgressBar();
  13.   13.             {
  14.   14.                 myProgressBar2.Maximum = 100;
  15.   15.                 backgroundWorker1.WorkerReportsProgress = true;
  16.   16.                 backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
  17.   17.                 backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
  18.   18.                 backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
  19.   19.             };
  20.   20.             backgroundWorker1.RunWorkerAsync(myProgressBar2);
  21.   21.  
  22.   22.
  23.   23.             myProgressBar2.Parent = this;
  24.   24.             myProgressBar2.Show();
  25.  
Oct 9 '10 #2
It didnt work so far.

I tried what you said but so far i cant see the progressbar after the splash screen.



This is what i have added to the constructor:
Expand|Select|Wrap|Line Numbers
  1. myProgressBar2 = new ProgressBar();
  2.             {
  3.                 myProgressBar2.Maximum = 100;
  4.                 myProgressBar2.Parent = this;
  5.                 myProgressBar2.Show();
  6.                 backgroundWorker1.WorkerReportsProgress = true;
  7.                 backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
  8.                 backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
  9.                 backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
  10.                 backgroundWorker1.RunWorkerAsync(myProgressBar2);
  11.             }
  12.  
I tried also to put this line after the Maximum=100;
Expand|Select|Wrap|Line Numbers
  1. this.Controls.Add(myProgressBar2);
  2.  
But this line didnt help either.

I tried to remove the {} in the constructor as above didnt help too.

Now this is the event of the backgroundworker1:


Expand|Select|Wrap|Line Numbers
  1. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  2.          {
  3.              for (int i = 0; i < 100; i++)
  4.              {
  5.                  Thread.Sleep(100);
  6.                  backgroundWorker1.ReportProgress(i);
  7.              }
  8.          }
  9.  
And the other two functions under it:


Expand|Select|Wrap|Line Numbers
  1. private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) //call back method 
  2.          {
  3.              myProgressBar2.Value = e.ProgressPercentage;
  4.          }
  5.          private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) //call back method 
  6.          {
  7.              myProgressBar2.Value = progressBar1.Maximum;
  8.  
  9.          }
  10.  

Whats wrong why i dont see the progressbar in the middle of the screen after the splash screen?



Thanks.
Oct 11 '10 #3
Plater
7,872 Expert 4TB
If your form hasn't loaded, how can it be drawing the progress bar?
Oct 13 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: silvastein | last post by:
Hi Friends. I have a table of deadlines that has fields for due date, item due, and person owed. The due dates span 2005, 2006 and 2007. I want to create a report that has a three columns of ...
2
by: androoo | last post by:
Hi I am learing how to use the grid in asp.net. Im trying to replace the button columns with nice friendly images. So : <asp:ButtonColumn Text="Delete"...
1
by: Lisa | last post by:
Hi, I'm trying to show some sign of activity while my app downloads a file from the internet. My download routine is such: Private Sub DownloadWebFile() Dim wdc As New System.Net.WebClient()...
1
by: Big George | last post by:
Trying to show a Crystal Report at WebForm1.aspx: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here...
4
by: Silvester | last post by:
Please can someone point me to a code sample where larges files can be dragdropped onto a form and files are copied using backgroundworker and progressbar status ? Thanks in advance
2
by: SergioQ | last post by:
Hi all, am trying to show a dollar figure on my webpage, but defining this for the cents value: font-size: 80%; vertical-align: super; just isn't cutting it! Is there a way to reduce the...
6
by: RFleming | last post by:
I am a pretty experienced VB programmer trying to make a jump to C#. I have created a simple (so I thought) project and seem to be stuck. I know I can create a form and write the code within the...
2
by: mcw.willart | last post by:
Hi, I use a backgroundworker to get the total size of a homeshare (as it is a bit time-consuming). Wat i would like to do, is show the progress, but at start i don't know how much files/folders...
8
by: Eps | last post by:
Hi there, Is there a way to get the progressbar value when a user clicks on it ? I am using wpf at the moment but windows forms solutions would be welcome too. I get the the x and y...
1
by: DanThMan | last post by:
Hi All, Here's how my data looks. Two tables. The first has all the data in "expanded" form, the second has just "ID" data in "pivoted" form. Here's the "expanded" table: DataID | RowID |...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.