????????????????????????EMP??
???????????? ???????[ 2013/4/7 10:23:29 ] ????????
??3?????
????1????? ***EventArgs???????***????????????? ***EventArgs??????????????????????????????
????2????????????????????Completed ??????????ɡ????????????????????????κ?????£???ó???????????????????????ó???????????????????????????ɡ?
????3???????????????????з??????κ?????????????????? Error ?????
????4????? ***CompletedEventArgs ?????????????????????????Σ??????λ???????????eg:public MyReturnType Result { get; }
????5??????? ***CompletedEventArgs ????????????this.RaiseExceptionIfNecessary()???????????????????á?Eg??
private bool isPrimeValue;
public bool IsPrime
{
get
{
RaiseExceptionIfNecessary();
return isPrimeValue;
}
}
???????????***Completed???????????У???????????? ***CompletedEventArgs.Error ?? ***CompletedEventArgs.Cancelled ?????????????RunWorkerCompletedEventArgs.Result?????
????BackgroundWorker???
????System.ComponentModel????????BackgroundWorker?????????????????????????y???????????????????????????????к????????????????????????????????????????????????????????????????????IsBusy?????ж?????????????AppDomain?????з???????????????AppDomain????ж???????????
????1??BackgroundWorker???
public class BackgroundWorker : Component
{
public BackgroundWorker();
// ?????????????ó????????????????????????
public bool CancellationPending { get; }
// ???????????BackgroundWorker???????????????????
public bool IsBusy { get; }
// ????????????????????BackgroundWorker????????????
public bool WorkerReportsProgress { get; set; }
// ????????????????????BackgroundWorker?????????????
public bool WorkerSupportsCancellation { get; set; }
// ????RunWorkerAsync() ???????
public event DoWorkEventHandlerDoWork;
// ????ReportProgress(System.Int32) ???????
public event ProgressChangedEventHandlerProgressChanged;
// ?????????????ɡ?????????????????????
public event RunWorkerCompletedEventHandlerRunWorkerCompleted;
// ????????????????????
public void CancelAsync();
// ????ProgressChanged?????percentProgress:??Χ?? 0% ??
public void ReportProgress(int percentProgress);
// userState:?????RunWorkerAsync(System.Object) ????????
public void ReportProgress(int percentProgress?? object userState);
// ?????к????????
public void RunWorkerAsync();
// ?????к????????argument:?????DoWork?????DoWorkEventArgs??????
public void RunWorkerAsync(object argument);
}
????2???????EventArgs??
///1) System.EventArgs????
// System.EventArgs???????????????????
public class EventArgs
{
// ???????????????????
public static readonly EventArgs Empty;
public EventArgs();
}
///2) DoWorkEventArgs??
// ??????????????????
public class CancelEventArgs : EventArgs
{
public CancelEventArgs();
public CancelEventArgs(bool cancel);
// ??????????????????????????
public bool Cancel { get; set; }
}
// ?DoWork?????????????????
public class DoWorkEventArgs : CancelEventArgs
{
public DoWorkEventArgs(object argument);
// ?????????????????????
public object Argument { get; }
// ?????????????????????????
public object Result { get; set; }
}
///3) ProgressChangedEventArgs??
// ?ProgressChanged??????????
public class ProgressChangedEventArgs : EventArgs
{
public ProgressChangedEventArgs(int progressPercentage?? object userState);
// ?????????????????
public int ProgressPercentage { get; }
// ????????????
public object UserState { get; }
}
///4) RunWorkerCompletedEventArgs??
// ?MethodNameCompleted??????????
public class AsyncCompletedEventArgs : EventArgs
{
public AsyncCompletedEventArgs();
public AsyncCompletedEventArgs(Exception error?? bool cancelled?? object userState);
// ???????????????????????????????
public bool Cancelled { get; }
// ??????????????????????????????
public Exception Error { get; }
// ????????????????
public object UserState { get; }
// ???? AsyncCompletedEventArgs ????????????????????????
protected void RaiseExceptionIfNecessary()
{
if (this.Error != null)
{
throw new TargetInvocationException(……);
}
if (this.Cancelled)
{
throw new InvalidOperationException(……);
}
}
}
public class RunWorkerCompletedEventArgs : AsyncCompletedEventArgs
{
public RunWorkerCompletedEventArgs(object result?? Exception error?? bool cancelled);
// ????????????????????
public object Result { get; }
// ????????????????
public object UserState { get; }
}
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11