Solved

Multi thread and progress bar

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

624 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