简体   繁体   中英

Gui async operations pattern?

I'm designing code for a download manager, and i was wondering if there are some good known patterns for the async operations?

I'm asking this because i have just started developing my own pattern.

Download a single file itself is an async operation with start, stop, pause, cancel, showing progress and speed. Download one big file can actually download many small files or parts, so this is one big operation that uses many sub-operations and the big operation should support start, stop, pause, cancel, showing progress and speed with fully consistency with the sub-operations.

After downloading, i should hash the file to validate it, and this is another operation.

You can see that i need a general way to handle all of those operations...

public interface IOperation
{
    event EventHandler<StateEventArgs> StartRequested;
    event EventHandler<StateEventArgs> Started;
    event EventHandler<ProgressEventArgs> ProgressChanged;
    event EventHandler<SpeedEventArgs> SpeedChanged;
    event EventHandler<StateEventArgs> PauseRequested;
    event EventHandler<StateEventArgs> Paused;
    event EventHandler<StateEventArgs> ContinueRequested;
    event EventHandler<StateEventArgs> Continued;
    event EventHandler<StateEventArgs> CancelRequested;
    event EventHandler<StateEventArgs> Cancelled;
    event EventHandler<StateEventArgs> Completed;
    event EventHandler<ExceptionEventArgs> WarningErrored;
    event EventHandler<ExceptionEventArgs> FatalErrored;

    OperationState OperationState { get; }
    ISynchronizeInvoke Invokable { get; set; }
    object State { get;set; }

    void StartAsync();
    void StartAsync(params object[] args);
    void StartSync();
    void StartSync(params object[] args);
    void Pause();
    void Continue();
    void Cancel();
}

模型视图控制器(MVC): http : //en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller这是以适当方式设计GUI的模式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM