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

  • SEARCH
  • Home
  • 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 6812529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:27:36+00:00 2026-05-26T20:27:36+00:00

i implemented a simple ProgressPresenter public interface IProgressView { string Status { set; }

  • 0

i implemented a simple ProgressPresenter

public interface IProgressView
{
    string Status { set; }
    void SetProgress(int percentageDone);

    void Display();
    void Close();

    event Action Closing;
}

class ProgressPresenter
{
    private IProgressView m_view;
    private ILongRunningTask m_task;
    private bool m_completed;

    public Progress(IProgressView view)
    {
        m_view = view;
    }

    public virtual void Display(ILongRunningTask task, string taskName)
    {
        m_task = task;

        m_view.Status = taskName " is running";

        m_view.Closing += OnClosing;
        task.ProgressChanged += UpdateProgress;
        task.Completed += Completed;

        task.StartAsync();

        m_view.Display();

        m_view.Closing -= OnClosing;
        task.ProgressChanged -= UpdateProgress;
        task.Completed -= Completed;
    }

    protected virtual void UpdateProgress(object sender, ProgessEventArgs e)
    {
        m_view.SetProgress(e.AlreadyDone * 100 / e.Total);
    }

    protected virtual void Completed()
    {
        m_completed = true;
        m_view.Status = "Completed";
        m_view.Close();
    }

    private virtual void OnClosing()
    {
        if (!m_completed) m_downloader.Cancel();
    }
}

My problem is that the task is running in another thread and each call to the view (implemented as a Form) throws. Should i wrap each method in the Form like

public string Status
{
    set { Invoke(new Action(() => progressLabel.Text = value)); }
}

just in case it could be called from another thread? or is the Presenter flawed?

Any advice is appreciated

  • 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-26T20:27:37+00:00Added an answer on May 26, 2026 at 8:27 pm

    Yes, you should do that.
    I don’t know what other libraries are you using, but is probably a good idea to add an aspect to all your views to do that for you.

    Also it might be worth adding a couple of friendly methods in a base view; E.g. I’ve got these ones:

        public void Invoke(Action action)
        {
            if (_control.InvokeRequired)
            {
                _control.Invoke(action);
                return;
            }
    
            action();
        }
    
        public T Invoke<T>(Func<T> action)
        {
            if (_control.InvokeRequired)
                return (T)_control.Invoke(action);
    
            return action();
        }
    

    for an example of the aspect implementation check here

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

Sidebar

Related Questions

I have the simple class using auto-implemented properies: Public Class foo { public foo()
I implemented simple server-client chat in Java. Here the source for the server: public
I've implemented a simple example of the Twitter @anywhere api to display user hovercards.
I have implemented a simple clock like so: - (void)runTimer { timer = [NSTimer
I have implemented a simple close() method for all the Backbone views which disposes
I have implemented a simple profiler with JVMTI to display the invocation on wait()
In my program, i implemented a simple database search that takes in a string
I implemented a simple sitemap class using Django's default sitemap application. As it was
I implemented a simple C# application which inserts about 350000 records into the database.
I implemented a simple matrix vector multiplication for sparse matrices in CRS using an

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.