public static BackgroundWorker WithHandlers(this BackgroundWorker bw, DoWorkDelegate doWorkDelegate, ProgressChangedDelegate progressChangedDelegate, RunWorkerCompletedDelegate runWorkerCompletedDelegate)
 {
     bw.DoWork += new DoWorkEventHandler((sender, dwe) => { doWorkDelegate(dwe); });
     bw.ProgressChanged += new ProgressChangedEventHandler((sender, pce) => { progressChangedDelegate(pce); });
     bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender, rwce) => { runWorkerCompletedDelegate(rwce); });
     return bw;
 }
예제 #2
0
        /// <summary>
        /// Occurs in case of progress change.
        /// </summary>
        /// <param name="e">ProgressChangedEventArgs.</param>
        protected virtual void OnProgressChanged(ProgressChangedEventArgs e)
        {
            ProgressChangedDelegate handler = ProgressChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
예제 #3
0
 public PeerConnectionManager(int localPort, string address, ProgressChangedDelegate progressChangedDelegate)
 {
     requestedFileListDelegate = new RequestedFileListDelegate(RequestedFileList);
     requestedFileDelegate = new RequestedFileDelegate(RequestedFile);
     cancelFileTransferDelegate = new CancelFileTransferDelegate(CancelFileTransfer);
     stopDelegate = new StopDelegate(this.StopThread);
     getFileFromPeerDelegate = new GetFileFromPeer(this.GetFileFromPeer);
     getFileListFromPeerDelegate = new GetFileListFromPeer(this.GetFileListFromPeer);
     this.progressChangedDelegate = progressChangedDelegate;
     this._localPort = localPort;
     this._localAddress = address;
 }
예제 #4
0
 public object DownloadFile(Uri uri, string fileName, DownloadCompleteDelegate onComplete, ProgressChangedDelegate onProgressChanged, object userData)
 {
     WebClient client = GetIdleClient();
     Handle handle = new Handle(uri, client, onComplete, onProgressChanged, userData);
     try
     {
         FileInfo file = new FileInfo(fileName);
         if (file.Exists)
             file.Delete();
         if (!file.Directory.Exists)
             file.Directory.Create();
         client.DownloadFileAsync(uri, fileName, handle);
     }
     catch (Exception)
     {
         client.CancelAsync();
         m_idleClients.Add(client);
         return null;
     }
     return handle;
 }
예제 #5
0
 public Handle(Uri uri, WebClient client, DownloadCompleteDelegate onComplete, ProgressChangedDelegate onProgressChanged, object userData)
 {
     this.startTime = DateTime.Now;
     this.uri = uri;
     this.client = client;
     this.onComplete = onComplete;
     this.onProgressChanged = onProgressChanged;
     this.complete = false;
     this.userData = userData;
 }