views:

101

answers:

2

Hi

I'm designing code for downloads manager, and i wonder if there is good known patterns for the async operations?

I asking it because i just started develope 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();
}
A: 

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.

Moisei
A: 

Webapp? AJAX! Native UI? Thread synchronization...

raoulsson
Winforms :P sorry for the confusion.
DxCK
Though I was missing something :-)
raoulsson