Giter VIP home page Giter VIP logo

Comments (2)

ramondeklein avatar ramondeklein commented on September 26, 2024

I think I see the problem... Reporting is done using the System.Progress<T> class. As can be read here these events are send to the synchronization context of the Progress<T> object during construction. This is the actual call that is being invoked when you call Progress.Report(...):

/// <summary>Reports a progress change.</summary>
/// <param name="value">The value of the updated progress.</param>
void IProgress<T>.Report(T value) { OnReport(value); }

/// <summary>Reports a progress change.</summary>
/// <param name="value">The value of the updated progress.</param>
protected virtual void OnReport(T value)
{
    // If there's no handler, don't bother going through the sync context.
    // Inside the callback, we'll need to check again, in case
    // an event handler is removed between now and then.
    Action<T>? handler = _handler;
    EventHandler<T>? changedEvent = ProgressChanged;
    if (handler != null || changedEvent != null)
    {
        // Post the processing to the sync context.
        // (If T is a value type, it will get boxed here.)
        _synchronizationContext.Post(_invokeHandlers, value);
    }
}

As you can see, it will perform a Post(...) on the synchronization context and that means that it will be invoked asynchronously. A Post(...) is a kind of fire-and-forget mechanism. So if your code runs fast, then the progress update is still in the queue and waiting to be dispatched, but the upload is already finished.

from minio-dotnet.

ramondeklein avatar ramondeklein commented on September 26, 2024

The reason that MS decided to use asynchronous posting of events in System.Progress<T> is probably, because progress is often used to provide feedback to the user. Most UI frameworks (at least WinForms and WPF) require that all UI updates are done on the main-thread. Because progress updates are normally not needed to be done in real-time (it doesn't matter that a progress updates is a few milliseconds late), using the SynchronizationContext is very convenient in UI applications.

The reason that they choose to Post() instead of Send() is not to block the caller. If they would have used Send(), then the call will be called synchronously on the progress thread and that would block processing and slow it down.

In a unit-test, there is no need for thread-synchronisation and using a callback that is invoked on an arbitrary thread is just fine.

from minio-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.