Solved

Multi thread and progress bar

Posted on 2004-09-30
6
315 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

763 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