Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 715795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:13:38+00:00 2026-05-14T05:13:38+00:00

I have code that does a web-service request. While doing this request I need

  • 0

I have code that does a web-service request.
While doing this request I need a progress-bar to be moving independently.

My problem is that I just need to say run a progress update every 1 or 2 seconds and check to see if progress of the request has been completed.

NetBasisServicesSoapClient client = new NetBasisServicesSoapClient();
            TransactionDetails[] transactions = new TransactionDetails[dataGridView1.Rows.Count - 1];
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                transactions[i] = new TransactionDetails();
                transactions[i].TransactionDate = (string)dataGridView1.Rows[i].Cells[2].Value;
                transactions[i].TransactionType = (string)dataGridView1.Rows[i].Cells[3].Value;
                transactions[i].Shares = (string)dataGridView1.Rows[i].Cells[4].Value;
                transactions[i].Pershare = (string)dataGridView1.Rows[i].Cells[5].Value;
                transactions[i].TotalAmount = (string)dataGridView1.Rows[i].Cells[6].Value;
            }
            CostbasisResult result = client.Costbasis(dataGridView1.Rows[0].Cells[0].Value.ToString(), dataGridView1.Rows[0].Cells[1].Value.ToString(), transactions, false, "", "", "FIFO", true);
            string result1 = ConvertStringArrayToString(result.Details);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:13:38+00:00Added an answer on May 14, 2026 at 5:13 am

    I use Background Workers all the time, they are great for processing long time actions.

    from your code

    #region Background Work of My Request
    
        private void ProcessMyRequest()
        {            
            if (!bkgWorkerMyRequest.IsBusy)
            {
                lblMessageToUser.Text = "Processing Request...";
                btnProcessRequest.Enabled = false;
                bkgWorkerMyRequest.RunWorkerAsync();
            }
        }
        private void bkgWorkerMyRequest_DoWork(object sender, DoWorkEventArgs e)
        {
            // let's process what we need in a diferrent thread than the UI thread
            string r = GetStuffDone();
            e.Result = r;
        }
        private void bkgWorkerMyRequest_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string myResult = (String)e.Result;    
    
            lblMessageToUser.Text = myResult;
            btnProcessRequest.Enabled = true;
        }
    
    #endregion
    
        private function string GetStuffDone() 
        {
            NetBasisServicesSoapClient client = new NetBasisServicesSoapClient();
            TransactionDetails[] transactions = new TransactionDetails[dataGridView1.Rows.Count - 1];
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                transactions[i] = new TransactionDetails();
                transactions[i].TransactionDate = (string)dataGridView1.Rows[i].Cells[2].Value;
                transactions[i].TransactionType = (string)dataGridView1.Rows[i].Cells[3].Value;
                transactions[i].Shares = (string)dataGridView1.Rows[i].Cells[4].Value;
                transactions[i].Pershare = (string)dataGridView1.Rows[i].Cells[5].Value;
                transactions[i].TotalAmount = (string)dataGridView1.Rows[i].Cells[6].Value;
            }
            CostbasisResult result = client.Costbasis(dataGridView1.Rows[0].Cells[0].Value.ToString(), dataGridView1.Rows[0].Cells[1].Value.ToString(), transactions, false, "", "", "FIFO", true);
            return ConvertStringArrayToString(result.Details);
        }
    

    all you need to do is call the method:

    ProcessMyRequest();
    

    and it will do the job. If you need to let the main Thread to be aware of progress, you can use the ProgressChanged event

    private void bkgWorkerMyRequest_ProgressChanged(
        object sender, ProgressChangedEventArgs e)
    {
        progressBar1.Value = e.ProgressPercentage;
    }
    

    in the bkgWorkerMyRequest_DoWork method you need to change the code to have

    //reports a percentage between 0 and 100
    bkgWorkerMyRequest.ReportProgress(i * 10); 
    

    Remember:

    alt text http://www.balexandre.com/temp/2010-04-07_1200.png

    You will, however get stuck when trying to Debug the method GetStuffDone as it’s that kinda hard debugging multi threaded applications

    So, what I do is, debug everything without workers and then apply the workers.

    Works fine for me, let me know if you need any more help on this.


    added

    I didn’t aware that you were getting the Grid in the worker, sorry, for this, just send the grid as a argument and use it, please change:

    bkgWorkerMyRequest.RunWorkerAsync(dataGridView1);
    
    string r = GetStuffDone((GridView)e.Argument);
    
    private function string GetStuffDone(GridView dataGridView1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just tested this and it worked for me: ta.text =… May 15, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer JQuery's .load() function is handy for loading data from a… May 15, 2026 at 5:14 pm
  • Editorial Team
    Editorial Team added an answer Assuming there's a foreign-key relationship between Customers & Orders, something… May 15, 2026 at 5:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.