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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:53:53+00:00 2026-06-05T18:53:53+00:00

I have a library with an Interface. Public Interface Progress { int ProgressValue{get;set;}, string

  • 0

I have a library with an Interface.

Public Interface Progress
{
    int ProgressValue{get;set;},
    string ProgressText{get;set;},
}

Library has a method Create (dummy code):

Public Class TestLibrary
{

    Progress _progress;

    Public void Create()
    {
        foreach(var n in TestList)
        {
            // Do Something
            _progress.ProgressValue = GetIndex(n);
            _progress.ProgressText = "Updating..." + n;
        }
    }
}

I have a project that references this library and calls Create method. It even Implements Interface Progress.

Public Class TestProject : Progress
{
    public int ProgressValue
    {
        get{return progressBar1.Value;}
        set{progressBar1.Value = value;}
    }

    public int ProgressText
    {
        get{return label1.Text;}
        set{label1.Text = value;}
    }
}

Now when I run the application, Progress Bar behaves properly and shows the progress correctly, but the Text of label1 does not change at all. But it do change in the end of for loop and shows the last item in loop. Can anyone help me out in this?

Note: All these codes are written directly without testing as I don’t have my application now with me. Sorry for any syntax errors.

  • 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-05T18:53:55+00:00Added an answer on June 5, 2026 at 6:53 pm

    Used a Label instead of ProgressBar. You can try this code [using BackGroundWorker] –

    using System.ComponentModel;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form3 : Form
        {
            private BackgroundWorker _worker;
            BusinessClass _biz = new BusinessClass();
            public Form3()
            {
                InitializeComponent();
                InitWorker();
            }
    
            private void InitWorker()
            {
                if (_worker != null)
                {
                    _worker.Dispose();
                }
    
                _worker = new BackgroundWorker
                {
                    WorkerReportsProgress = true,
                    WorkerSupportsCancellation = true
                };
                _worker.DoWork += DoWork;
                _worker.RunWorkerCompleted += RunWorkerCompleted;
                _worker.ProgressChanged += ProgressChanged;
                _worker.RunWorkerAsync();
            }
    
    
            void DoWork(object sender, DoWorkEventArgs e)
            {
                int highestPercentageReached = 0;
                if (_worker.CancellationPending)
                {
                    e.Cancel = true;
                }
                else
                {
                    double i = 0.0d;
                    int junk = 0;
                    for (i = 0; i <= 199990000; i++)
                    {
                        int result = _biz.MyFunction(junk);
                        junk++;
    
                        // Report progress as a percentage of the total task.
                        var percentComplete = (int)(i / 199990000 * 100);
                        if (percentComplete > highestPercentageReached)
                        {
                            highestPercentageReached = percentComplete;
                            // note I can pass the business class result also and display the same in the LABEL  
                            _worker.ReportProgress(percentComplete, result);
                            _worker.CancelAsync();
                        }
                    }
    
                }
            }
    
            void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                if (e.Cancelled)
                {
                    // Display some message to the user that task has been
                    // cancelled
                }
                else if (e.Error != null)
                {
                    // Do something with the error
                }
            }
    
            void ProgressChanged(object sender, ProgressChangedEventArgs e)
            {
                label1.Text =  string.Format("Result {0}: Percent {1}",e.UserState, e.ProgressPercentage);
            }
        }
    
        public class BusinessClass
        {
            public int MyFunction(int input)
            {
                return input+10;
            }
        }
    }
    

    Posted the same a few days ago here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this: MathServiceLibrary (WCF Service Library) [ServiceContract] public interface IMathService {
I have a library that contains some public interfaces. Before each public interface there
I am writing a library and I want to have an interface public interface
I have a third-party library (the interface to Xerox's Finite State tools) which come
I have created a WCF service interface and implementation in a Class Library. I
I have refactored some UIView sub-classes into a static library. However, when using Interface
I'm writing myself a class library to manage Active Directory. I have an interface:
Assuming that I have the following interface and class: public interface IFooRepo : IDisposable
I have: Main Program Class - uses Library A Library A - has partial
I have something like following: public interface A { .... } public abstract class

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.