开发者

Gui async operations pattern?

开发者 https://www.devze.com 2022-12-13 06:38 出处:网络
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 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;

    Op开发者_C百科erationState 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();
}


Model-View-Controller (MVC): http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller This is the pattern to design a GUI in proper way.

0

精彩评论

暂无评论...
验证码 换一张
取 消