469,610 Members | 1,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

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 13341
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by dixp | last post: by
1 post views Thread by Imran | last post: by
55 posts views Thread by Sam | last post: by
4 posts views Thread by Michael | last post: by
6 posts views Thread by David Veeneman | last post: by
6 posts views Thread by dgleeson3 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.