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 8610069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:02:31+00:00 2026-06-12T04:02:31+00:00

I have a backgroundworker to proccess some work, there is a loop in do_work

  • 0

I have a backgroundworker to proccess some work, there is a loop in do_work event and from within i am calling reportprogress with counter, the counter is incrementing but progressbar not moving. If i use a simple for loop from 1 to 100 calling reportprogress the progress bar works.
sorry for ammount of code..

namespace ConvertOSGB_WGS84
{
public partial class InterfaceConvertLonLat : Form
{
    public static Int32 OGB_M = 150;
    [DllImport("TTDatum3.Dll", EntryPoint = "WGS84ToLocal", CallingConvention =  CallingConvention.StdCall, SetLastError = true)]
    public static extern Int32 WGS84ToLocal([In, Out]ref double lat, [In, Out] ref double lon, Int32 datum);

    [DllImport("TTDatum3.Dll", EntryPoint = "LocalToWGS84", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    public static extern Int32 LocalToWGS84([In, Out]ref double lat, [In, Out] ref double lon, Int32 datum);

    [DllImport("TTDatum3.Dll", EntryPoint = "OSGB36ToOSGBGrid", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    public static extern Int32 OSGB36ToOSGBGrid(double lat, double lon, [In, Out] ref double east, [In, Out] ref double north);

    [DllImport("TTDatum3.Dll", EntryPoint = "OSGBGridToOSGB36", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    public static extern Int32 OSGBGridToOSGB36(double east, double north, [In, Out] ref double lat, [In, Out]  ref double lon);
    CovertLonLat convert = new CovertLonLat();


    public InterfaceConvertLonLat()
    {
        InitializeComponent();
        Shown += new EventHandler(Form1_Shown);
        backgroundWorker1.WorkerReportsProgress = true;
        backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
        backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);

    }
    public void ConvertLonLat_Load(object sender, EventArgs e)
    {

    }

    public void Form1_Shown(object sender, EventArgs e)
    {     
        backgroundWorker1.RunWorkerAsync();
    }

    public void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        MessageBox.Show("backgroundworker");
        SqlConnection conn = new SqlConnection(Connections.dbConnection1());
        InterfaceConvertLonLat con = new InterfaceConvertLonLat();
        SqlCommand cmd = new SqlCommand();
        SqlCommand cmd1 = new SqlCommand();
        SqlDataAdapter adapter = new SqlDataAdapter();
        DataSet address = new DataSet();
        int counter = 0;


        cmd.Parameters.Clear();

        if (conn.State.Equals(System.Data.ConnectionState.Closed))
        {
            conn.Open();
        }
        try
        {
            adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            cmd1.Parameters.Add(new SqlParameter("@LTW", SqlDbType.Float));
            cmd1.Parameters.Add(new SqlParameter("@LGW", SqlDbType.Float));


            string dbQuery = "select * from paf ";

            cmd.CommandText = (dbQuery);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = conn;
            adapter.SelectCommand = cmd;
            adapter.Fill(address, "OBG36ToWGS84");

            foreach (DataRow LonLat in address.Tables[0].Rows)
            {
                counter++;
                MessageBox.Show("value " + counter);
                con.backgroundWorker1.ReportProgress(counter);
                Double lon = 0;
                Double lat = 0;

                lat = Convert.ToDouble(LonLat["LTO"]);
                lon = Convert.ToDouble(LonLat["LGO"]);
                LocalToWGS84(ref lat, ref lon, OGB_M);

                cmd1.Parameters["@LTW"].Value = lat;
                cmd1.Parameters["@LGW"].Value = lon;

                string dbQuery1 = "update paf set LTW = @LTW, LGW = @LGW";

                cmd1.CommandText = (dbQuery1);
                cmd1.CommandType = CommandType.Text;
                cmd1.Connection = conn;
                cmd1.ExecuteNonQuery();

            }
        }
        catch (Exception ex)
        {

            MessageBox.Show("error converting: " + ex.Message);
        }
        finally
        {

            conn.Close();

        }
    }

    public void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {

         progressBar1.Value = e.ProgressPercentage;
    }




}

}

  • 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-06-12T04:02:32+00:00Added an answer on June 12, 2026 at 4:02 am

    This is the problem:

    InterfaceConvertLonLat con = new InterfaceConvertLonLat();
    ...
    con.backgroundWorker1.ReportProgress(counter);
    

    So you’re reporting progress on a different background worker – one which is associated with a form which isn’t shown. Just use:

    backgroundWorker1.ReportProgress(counter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button that on click event I get some information from the
Essentially, I have a Do..While loop going through some lines from a text file.
I have some code which is been running by a backgroundworker I'd like some
I have a WPF ListView that I am trying to filter within a BackgroundWorker.
I have a system whereby users can upload sometimes large(100-200 MB) files from within
I have a background thread doing some work and a UI displaying the progress,
I have an ASP.NET site and I've been doing some work refactoring code to
I have some code inside a background worker DoWork event which check if a
I have a multi-step BackgroundWorker process. I use a marquee progress bar because several
I have a longer running multi-step process using BackgroundWorker and C#. I need to

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.