473,394 Members | 1,902 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,394 software developers and data experts.

Multithreading and progress bar help

Dear experts, i want to develop an client application that consume the google
search web service.
In my MainForm i have a method to retrieve all the search result e.g.
GetGoogleResults().
Now i want to have a nice progress bar in another form e.g ProgressForm to
perform the search action.
i tried to do it but the progress bar won't work and the GUI freezed.
I knew how to do with the single threading but i don't know how to do it in
multiple threading.
Could anyone give me an example of how to do that.
Thank you
Nov 16 '05 #1
9 13579
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Dear experts, i want to develop an client application that consume the google
search web service.
In my MainForm i have a method to retrieve all the search result e.g.
GetGoogleResults().
Now i want to have a nice progress bar in another form e.g ProgressForm to
perform the search action.
i tried to do it but the progress bar won't work and the GUI freezed.
I knew how to do with the single threading but i don't know how to do it in
multiple threading.
Could anyone give me an example of how to do that.


See http://www.pobox.com/~skeet/csharp/t...winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Here is my program but i still don't know how to make the progress bar work,
please help me. The program simply download the list of web services from
strike iron business network
Thank you

---MainForm.cs-----------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace TestProgressBar
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class MainForm: System.Windows.Forms.Form
{
private System.Windows.Forms.Button GetWebServices;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private const string licenseKey = "ADBBB86C6FAA29E47337";
com.strikeiron.www.WebServiceInfo [] wsList;
ProgressForm prg = new ProgressForm();

public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.GetWebServices = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// GetWebServices
//
this.GetWebServices.Location = new System.Drawing.Point(96, 24);
this.GetWebServices.Name = "GetWebServices";
this.GetWebServices.Size = new System.Drawing.Size(120, 23);
this.GetWebServices.TabIndex = 0;
this.GetWebServices.Text = "Get Web Services";
this.GetWebServices.Click += new
System.EventHandler(this.GetWebServices_Click);
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(320, 86);
this.Controls.Add(this.GetWebServices);
this.Name = "MainForm";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

private void GetWebServices_Click(object sender, System.EventArgs e)
{
//Show the progressform
prg.Show();
Thread t1 = new Thread(new ThreadStart(GetWebServiceListHandler));
t1.Start();
}

//This will get the list of strike iron web service business network
private com.strikeiron.www.WebServiceInfo [] GetWebServiceList()
{
com.strikeiron.www.WebServiceInfo [] wsList;
com.strikeiron.www.StrikeIronDirectoryService myService;
com.strikeiron.www.LicStatus liSta;
com.strikeiron.www.RespStatus resSta;
myService = new com.strikeiron.www.StrikeIronDirectoryService();
liSta = new com.strikeiron.www.LicStatus();
resSta = new com.strikeiron.www.RespStatus();

//Get the list
wsList = myService.GetAllPublicServices(licenseKey,out resSta,out liSta);

return wsList;

}

private void GetWebServiceListHandler()
{
//start the time
timer1.Start();
this.wsList = GetWebServiceList();
//stop the time
timer1.Stop();
prg.UpdateLabel(wsList.Length + "web services have been found");
}

//Update the progress
private void timer1_Tick(object sender, System.EventArgs e)
{
prg.UpdateProgress();
}


}
}
---------ProgressForm.cs--------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestProgressBar
{
/// <summary>
/// Summary description for Form2.
/// </summary>
public class ProgressForm : System.Windows.Forms.Form
{
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public ProgressForm ()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
InitProgressBar();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(24, 40);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(240, 23);
this.progressBar1.TabIndex = 0;
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(240, 23);
this.label1.TabIndex = 1;
this.label1.Text = "Please wait";
//
// ProgressForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(296, 86);
this.Controls.Add(this.label1);
this.Controls.Add(this.progressBar1);
this.Name = "ProgressForm";
this.Text = "Form2";
this.ResumeLayout(false);

}
#endregion

public void UpdateProgress()
{
if(progressBar1.Value>0 && progressBar1.Value<100)
progressBar1.Value++;
}

private void InitProgressBar()
{
progressBar1.Minimum = 1;
progressBar1.Maximum = 100;
}

public void UpdateLabel(string value)
{
label1.Text = value;
}
}

}

----------StrikeIron Web services--------
http://www.strikeiron.com/webservice...vice.asmx?wsdl
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Take a look at the archives, I posted some code to do this like two weeks
ago.

Search for something like ProgressBar Thread "Ignacio Machin", dont worry,.
I did that for you :) :

http://groups.google.com/groups?q=Pr...phx.gbl&rnum=2

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Popoxinhxan" <Po*********@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Dear experts, i want to develop an client application that consume the

google
search web service.
In my MainForm i have a method to retrieve all the search result e.g.
GetGoogleResults().
Now i want to have a nice progress bar in another form e.g ProgressForm to
perform the search action.
i tried to do it but the progress bar won't work and the GUI freezed.
I knew how to do with the single threading but i don't know how to do it

in
multiple threading.
Could anyone give me an example of how to do that.
Thank you


Nov 16 '05 #3
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Here is my program but i still don't know how to make the progress bar work,
please help me. The program simply download the list of web services from
strike iron business network


You're still not using Control.Invoke or BeginInvoke. Did you read the
page I pointed you at,
http://www.pobox.com/~skeet/csharp/t...winforms.shtml

?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Actually i quite not understand the method begin invoke and invoke clearly,
could you explain how to use those and when will we need to use.
Thank you

"Jon Skeet [C# MVP]" wrote:
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Here is my program but i still don't know how to make the progress bar work,
please help me. The program simply download the list of web services from
strike iron business network


You're still not using Control.Invoke or BeginInvoke. Did you read the
page I pointed you at,
http://www.pobox.com/~skeet/csharp/t...winforms.shtml

?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Actually i quite not understand the method begin invoke and invoke clearly,
could you explain how to use those and when will we need to use.


I've explained it as best I can in the article I pointed you at. I
suggest you read the article right from the start (the page I pointed
you at is somewhere in the middle) and ask any specific questions that
aren't answered in there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Your article you pointed for me is very helpful, it help me a lot to
understand more about threading. However there is a problem that i still
don't know how to apply multithreading in my application (my brain freezed),
I would appreciated that if you could guide me how to do in my application
specially how to retrieve information from different thread.
Again thank you so much.

"Jon Skeet [C# MVP]" wrote:
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Actually i quite not understand the method begin invoke and invoke clearly,
could you explain how to use those and when will we need to use.


I've explained it as best I can in the article I pointed you at. I
suggest you read the article right from the start (the page I pointed
you at is somewhere in the middle) and ask any specific questions that
aren't answered in there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Your article you pointed for me is very helpful, it help me a lot to
understand more about threading. However there is a problem that i still
don't know how to apply multithreading in my application (my brain freezed),
I would appreciated that if you could guide me how to do in my application
specially how to retrieve information from different thread.
Again thank you so much.


I'm afraid I've given everything I can in the article - I'd only be
repeating what it says there. Does the example in the Windows Forms
section not help you?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
Thank for your help i will try to work out your sample application to see how
it work(i've just read your article and try to apply to my program only) and
then ask more detail about that

"Jon Skeet [C# MVP]" wrote:
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Your article you pointed for me is very helpful, it help me a lot to
understand more about threading. However there is a problem that i still
don't know how to apply multithreading in my application (my brain freezed),
I would appreciated that if you could guide me how to do in my application
specially how to retrieve information from different thread.
Again thank you so much.


I'm afraid I've given everything I can in the article - I'd only be
repeating what it says there. Does the example in the Windows Forms
section not help you?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9
Hi,

The example I gave you should work fine, did you tried it?

Multithreading is not simple, it is one of the most complex matter in
computing, and can be confusing, so I suggest you that you start reading
jon's article and practicing with some console application before making
multitheading win apps.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Popoxinhxan" <Po*********@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
Thank for your help i will try to work out your sample application to see how it work(i've just read your article and try to apply to my program only) and then ask more detail about that

"Jon Skeet [C# MVP]" wrote:
Popoxinhxan <Po*********@discussions.microsoft.com> wrote:
Your article you pointed for me is very helpful, it help me a lot to
understand more about threading. However there is a problem that i still don't know how to apply multithreading in my application (my brain freezed), I would appreciated that if you could guide me how to do in my application specially how to retrieve information from different thread.
Again thank you so much.


I'm afraid I've given everything I can in the article - I'd only be
repeating what it says there. Does the example in the Windows Forms
section not help you?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
1
by: Imran | last post by:
I have an asp.net application that uses multithreading to allow for progress bar aproach while its doing its work in the backgroung in the secondary thread. the main thread is just refreshing the...
55
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to...
4
by: Michael | last post by:
Hi, I am trying to create a multithreaded VB 2005 application which attempts to create a new thread per Domain Controller (DC) in my environment. Each thread connects to its allocated DC and...
6
by: David Veeneman | last post by:
I am looking for a resource to learn how to do multithreading in a data bound app. So far, I have figured out that I can't update a databound object on a worker thread, because that triggers a...
1
by: martin-g | last post by:
Hi. Some time ago I wrote a specialized Excel files merging tool using Access. Input .xls files can be extremely large, so calculation required for merging may last for a long. I have realized a...
6
by: dgleeson3 | last post by:
Hello All Im having lots of fun with window handles and invoke. The code started off in a single class. Main thread set up a worker thread and the worker thread updated the progress bar on...
0
by: waghmarerajendra | last post by:
I am working in .NET compact framework 1.1 and developing WINCE based application and running it on .NET emulator. I am developing an application where there is an UI and some background...
0
by: blaze641983 | last post by:
OK... here goes. I'm not new to VB.net, but I AM new to multi-threading. Bust all you want about searching, but I hate reading hundreds of threads trying to find an answer to my problem when I...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.