123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System;
- using System.ComponentModel;
- using System.Net;
- using System.Threading;
- using Update.Net.Events;
- namespace Update.Net
- {
-
-
-
- [ToolboxItem(false)]
- public partial class UpdateClient : WebClient
- {
- private bool m_InitAsync;
- private bool m_Cancelled;
- private int m_CallNesting;
- private AsyncOperation m_AsyncOp;
- private ProgressData m_Progress;
- #region 属性
-
-
-
- public new virtual bool IsBusy
- {
- get
- {
- return base.IsBusy || this.m_AsyncOp != null;
- }
- }
- #endregion
- #region 状态
-
-
-
- private void InitAsync()
- {
- if (this.m_InitAsync)
- return;
- this.m_Progress = new ProgressData();
- this.m_KillProcessStart = new KillProcessStartDelegate(this.KillProcessWork);
- this.m_ReportKillProgressChanged = new SendOrPostCallback(this.ReportKillProgressChanged);
- this.m_KillProcessOperationCompleted = new SendOrPostCallback(this.KillProcessOperationCompleted);
- this.m_DecompressDataStart = new DecompressDataStartDelegate(this.DecompressDataWork);
- this.m_ReportDecompressProgressChanged = new SendOrPostCallback(this.ReportDecompressProgressChanged);
- this.m_DecompressDataOperationCompleted = new SendOrPostCallback(this.DecompressDataOperationCompleted);
- this.m_InitAsync = true;
- }
-
-
-
- private void ClearState()
- {
- if (this.AnotherCallInProgress(Interlocked.Increment(ref this.m_CallNesting)))
- {
- this.CompleteState();
- throw new NotSupportedException("无效的操作,操作占用中。");
- }
- this.m_Cancelled = false;
- if (this.m_Progress != null)
- this.m_Progress.Reset();
- }
-
-
-
- private void CompleteState()
- {
- Interlocked.Decrement(ref m_CallNesting);
- }
-
-
-
-
-
- private bool AnotherCallInProgress(int callNesting)
- {
- return callNesting > 1;
- }
- #endregion
- #region 执行回调
-
-
-
-
-
-
- private void InvokeOperation(AsyncOperation asyncOp, SendOrPostCallback callback, object eventArgs)
- {
- asyncOp.Post(callback, eventArgs);
- }
-
-
-
-
-
-
- private void InvokeOperationCompleted(AsyncOperation asyncOp, SendOrPostCallback callback, AsyncCompletedEventArgs eventArgs)
- {
- if (Interlocked.CompareExchange(ref this.m_AsyncOp, null, asyncOp) == asyncOp)
- {
- this.CompleteState();
- asyncOp.PostOperationCompleted(callback, eventArgs);
- }
- }
- #endregion
- #region 公共方法
-
-
-
- public new virtual void CancelAsync()
- {
- this.m_Cancelled = true;
- base.CancelAsync();
- }
- #endregion
- }
- }
|