Solved

Multi thread and progress bar

Posted on 2004-09-30
6
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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