Solved

Multi thread and progress bar

Posted on 2004-09-30
6
311 Views
Last Modified: 2008-03-10
Dear all,
I have 2 forms, the first form is the main form which have a button to get the list data from database and second form is the progress form which simple have the progress bar and progress status.The problem i have is that when i click the button to retrieve the data, the UI is freezed for both main form and the progress form. My classmate told me that i should use threading to fix the problem however i don't know how to do it. , i already research in thread but still don't know how to apply to this problem could someone help me to do it or give me some similar example.
Thank you very much
0
Comment
Question by:contran
  • 2
6 Comments
 
LVL 10

Expert Comment

by:123654789987
ID: 12188497
U have to use delegates to achieve this functionality.

Say in form1. U have a progress bar. In form2 u have some methods which do database operations.

In Form1

Form2 frm2 = new Form2;

 progressbar.Maximum = 9;
 progressbar.Minimum = 0;
 
frm2. DataBaseMethod();

U need to have another method in Form1 that updates the progressbar

 Private ETL_UpdateStatus( int currentCount)
{
        progressbar.Increment(currentCount);
 }
 

In Form2 u have event

 Public Event UpdateStatus(int currentCount)

and a function DatabaseMethod

public DatabaseMethod()
{
  //Here u raise the event
RaiseEvent UpdateStatus(0)
.....
RaiseEvent UpdateStatus(9)
}


I think a better explanation of this is given in this link

http://blog.andrewcarlson.org/archive/2004/07/28/338.aspx





 



0
 
LVL 10

Accepted Solution

by:
123654789987 earned 250 total points
ID: 12188512
Another good example for your requirement

http://www.codeproject.com/csharp/threader.asp
0
 

Author Comment

by:contran
ID: 12196801
Thank you for your point to the article however i think the article is more advance and i still confusing to make it. Could you please give me more explanation
Here is the work
I simply consume the strike iron search web services which returns a list of the web services in its business directory. In my first form i have a list view, a button to retrieve the list. In my second form basically is just contains a progress bar and the status. Here is the code
-----Main Form-----
//StrikeIron License key
public string licensekey = "";

//The method to retrieve the list
private com.strikeiron.www.WebServiceInfo [] GetWebServicesList (){
  com.strikeiron.www.StrikeIronDirectoryService service =
               new  com.strikeiron.www.StrikeIronDirectoryService();
  com.strikeiron.www.LicStatus lic = new com.strikeiron.www.LicStatus();
  com.strikeiron.www.RespStatus res = new strikeiron.www.RespStatus();
  com.strikeiron.www.WebServiceInfo [] list = null;
 
  try{
      list = service.GetAllPublicServices(this.licenseKey,out res,out lic);
  }catch (System.Net.WebException) {
      MessageBox.Show(this,"Check your internet connection","Connection Error");
  }

  return list;
}

--- Second Form ---
public void UpdateProgress()
{
  if(this.progressBar1.Value < this.progressBar1.Maximum)
       progressBar1.Value++;
}

public void UpdateStatus(string status)
{
    this.lblStatus.Text = status;
}

----Web services url -----
http://www.strikeiron.com/webservices/StrikeIronDirectoryService.asmx?wsdl

My aim is trying to display the progress form to show the % of the data is retrieving. How can i apply your suggestion in my MainForm and the ProgressForm. Please help me to do so.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

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

17 Experts available now in Live!

Get 1:1 Help Now