Solved

Multi thread and progress bar

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C#.NET and microsoft certification. 3 40
Close form "before" open 3 40
How can i use linq for parsing string datetime to real datetime? 16 44
FTP file download using c# 3 22
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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