253 lines
10 KiB
C#
253 lines
10 KiB
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace System.ComponentModel
|
|
{
|
|
/// <summary>Executes an operation on a separate thread.</summary>
|
|
// Token: 0x02000058 RID: 88
|
|
public class BackgroundWorker
|
|
{
|
|
/// <summary>Occurs when <see cref="M:System.ComponentModel.BackgroundWorker.RunWorkerAsync" /> is called.</summary>
|
|
// Token: 0x14000010 RID: 16
|
|
// (add) Token: 0x06000366 RID: 870 RVA: 0x0000A7C0 File Offset: 0x000089C0
|
|
// (remove) Token: 0x06000367 RID: 871 RVA: 0x0000A7DC File Offset: 0x000089DC
|
|
public event DoWorkEventHandler DoWork;
|
|
|
|
/// <summary>Occurs when <see cref="M:System.ComponentModel.BackgroundWorker.ReportProgress(System.Int32)" /> is called.</summary>
|
|
// Token: 0x14000011 RID: 17
|
|
// (add) Token: 0x06000368 RID: 872 RVA: 0x0000A7F8 File Offset: 0x000089F8
|
|
// (remove) Token: 0x06000369 RID: 873 RVA: 0x0000A814 File Offset: 0x00008A14
|
|
public event ProgressChangedEventHandler ProgressChanged;
|
|
|
|
/// <summary>Occurs when the background operation has completed, has been canceled, or has raised an exception.</summary>
|
|
// Token: 0x14000012 RID: 18
|
|
// (add) Token: 0x0600036A RID: 874 RVA: 0x0000A830 File Offset: 0x00008A30
|
|
// (remove) Token: 0x0600036B RID: 875 RVA: 0x0000A84C File Offset: 0x00008A4C
|
|
public event RunWorkerCompletedEventHandler RunWorkerCompleted;
|
|
|
|
/// <summary>Gets a value indicating whether the application has requested cancellation of a background operation.</summary>
|
|
/// <returns>true if the application has requested cancellation of a background operation; otherwise, false. The default is false.</returns>
|
|
// Token: 0x170000EF RID: 239
|
|
// (get) Token: 0x0600036C RID: 876 RVA: 0x0000A868 File Offset: 0x00008A68
|
|
public bool CancellationPending
|
|
{
|
|
get
|
|
{
|
|
return this.cancel_pending;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets a value indicating whether the <see cref="T:System.ComponentModel.BackgroundWorker" /> is running an asynchronous operation.</summary>
|
|
/// <returns>true, if the <see cref="T:System.ComponentModel.BackgroundWorker" /> is running an asynchronous operation; otherwise, false.</returns>
|
|
// Token: 0x170000F0 RID: 240
|
|
// (get) Token: 0x0600036D RID: 877 RVA: 0x0000A870 File Offset: 0x00008A70
|
|
public bool IsBusy
|
|
{
|
|
get
|
|
{
|
|
return this.async != null;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets or sets a value indicating whether the <see cref="T:System.ComponentModel.BackgroundWorker" /> can report progress updates.</summary>
|
|
/// <returns>true if the <see cref="T:System.ComponentModel.BackgroundWorker" /> supports progress updates; otherwise false. The default is false.</returns>
|
|
// Token: 0x170000F1 RID: 241
|
|
// (get) Token: 0x0600036E RID: 878 RVA: 0x0000A880 File Offset: 0x00008A80
|
|
// (set) Token: 0x0600036F RID: 879 RVA: 0x0000A888 File Offset: 0x00008A88
|
|
[DefaultValue(false)]
|
|
public bool WorkerReportsProgress
|
|
{
|
|
get
|
|
{
|
|
return this.report_progress;
|
|
}
|
|
set
|
|
{
|
|
this.report_progress = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets or sets a value indicating whether the <see cref="T:System.ComponentModel.BackgroundWorker" /> supports asynchronous cancellation.</summary>
|
|
/// <returns>true if the <see cref="T:System.ComponentModel.BackgroundWorker" /> supports cancellation; otherwise false. The default is false.</returns>
|
|
// Token: 0x170000F2 RID: 242
|
|
// (get) Token: 0x06000370 RID: 880 RVA: 0x0000A894 File Offset: 0x00008A94
|
|
// (set) Token: 0x06000371 RID: 881 RVA: 0x0000A89C File Offset: 0x00008A9C
|
|
[DefaultValue(false)]
|
|
public bool WorkerSupportsCancellation
|
|
{
|
|
get
|
|
{
|
|
return this.support_cancel;
|
|
}
|
|
set
|
|
{
|
|
this.support_cancel = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Requests cancellation of a pending background operation.</summary>
|
|
/// <exception cref="T:System.InvalidOperationException">
|
|
/// <see cref="P:System.ComponentModel.BackgroundWorker.WorkerSupportsCancellation" /> is false. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x06000372 RID: 882 RVA: 0x0000A8A8 File Offset: 0x00008AA8
|
|
public void CancelAsync()
|
|
{
|
|
if (!this.support_cancel)
|
|
{
|
|
throw new InvalidOperationException("This background worker does not support cancellation.");
|
|
}
|
|
if (!this.IsBusy)
|
|
{
|
|
return;
|
|
}
|
|
this.cancel_pending = true;
|
|
}
|
|
|
|
/// <summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" /> event.</summary>
|
|
/// <param name="percentProgress">The percentage, from 0 to 100, of the background operation that is complete. </param>
|
|
/// <exception cref="T:System.InvalidOperationException">The <see cref="P:System.ComponentModel.BackgroundWorker.WorkerReportsProgress" /> property is set to false. </exception>
|
|
// Token: 0x06000373 RID: 883 RVA: 0x0000A8D4 File Offset: 0x00008AD4
|
|
public void ReportProgress(int percentProgress)
|
|
{
|
|
this.ReportProgress(percentProgress, null);
|
|
}
|
|
|
|
/// <summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" /> event.</summary>
|
|
/// <param name="percentProgress">The percentage, from 0 to 100, of the background operation that is complete.</param>
|
|
/// <param name="userState">The state object passed to <see cref="M:System.ComponentModel.BackgroundWorker.RunWorkerAsync(System.Object)" />.</param>
|
|
/// <exception cref="T:System.InvalidOperationException">The <see cref="P:System.ComponentModel.BackgroundWorker.WorkerReportsProgress" /> property is set to false. </exception>
|
|
// Token: 0x06000374 RID: 884 RVA: 0x0000A8E0 File Offset: 0x00008AE0
|
|
public void ReportProgress(int percentProgress, object userState)
|
|
{
|
|
if (!this.WorkerReportsProgress)
|
|
{
|
|
throw new InvalidOperationException("This background worker does not report progress.");
|
|
}
|
|
if (!this.IsBusy)
|
|
{
|
|
return;
|
|
}
|
|
this.async.Post(delegate(object o)
|
|
{
|
|
ProgressChangedEventArgs progressChangedEventArgs = o as ProgressChangedEventArgs;
|
|
this.OnProgressChanged(progressChangedEventArgs);
|
|
}, new ProgressChangedEventArgs(percentProgress, userState));
|
|
}
|
|
|
|
/// <summary>Starts execution of a background operation.</summary>
|
|
/// <exception cref="T:System.InvalidOperationException">
|
|
/// <see cref="P:System.ComponentModel.BackgroundWorker.IsBusy" /> is true.</exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x06000375 RID: 885 RVA: 0x0000A930 File Offset: 0x00008B30
|
|
public void RunWorkerAsync()
|
|
{
|
|
this.RunWorkerAsync(null);
|
|
}
|
|
|
|
// Token: 0x06000376 RID: 886 RVA: 0x0000A93C File Offset: 0x00008B3C
|
|
private void ProcessWorker(object argument, AsyncOperation async, SendOrPostCallback callback)
|
|
{
|
|
Exception ex = null;
|
|
DoWorkEventArgs doWorkEventArgs = new DoWorkEventArgs(argument);
|
|
try
|
|
{
|
|
this.OnDoWork(doWorkEventArgs);
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
ex = ex2;
|
|
doWorkEventArgs.Cancel = false;
|
|
}
|
|
callback(new object[]
|
|
{
|
|
new RunWorkerCompletedEventArgs(doWorkEventArgs.Result, ex, doWorkEventArgs.Cancel),
|
|
async
|
|
});
|
|
}
|
|
|
|
// Token: 0x06000377 RID: 887 RVA: 0x0000A9B0 File Offset: 0x00008BB0
|
|
private void CompleteWorker(object state)
|
|
{
|
|
object[] array = (object[])state;
|
|
RunWorkerCompletedEventArgs runWorkerCompletedEventArgs = array[0] as RunWorkerCompletedEventArgs;
|
|
AsyncOperation asyncOperation = array[1] as AsyncOperation;
|
|
SendOrPostCallback sendOrPostCallback = delegate(object darg)
|
|
{
|
|
this.async = null;
|
|
this.OnRunWorkerCompleted(darg as RunWorkerCompletedEventArgs);
|
|
};
|
|
asyncOperation.PostOperationCompleted(sendOrPostCallback, runWorkerCompletedEventArgs);
|
|
this.cancel_pending = false;
|
|
}
|
|
|
|
/// <summary>Starts execution of a background operation.</summary>
|
|
/// <param name="argument">A parameter for use by the background operation to be executed in the <see cref="E:System.ComponentModel.BackgroundWorker.DoWork" /> event handler. </param>
|
|
/// <exception cref="T:System.InvalidOperationException">
|
|
/// <see cref="P:System.ComponentModel.BackgroundWorker.IsBusy" /> is true. </exception>
|
|
// Token: 0x06000378 RID: 888 RVA: 0x0000A9F4 File Offset: 0x00008BF4
|
|
public void RunWorkerAsync(object argument)
|
|
{
|
|
if (this.IsBusy)
|
|
{
|
|
throw new InvalidOperationException("The background worker is busy.");
|
|
}
|
|
this.async = AsyncOperationManager.CreateOperation(this);
|
|
BackgroundWorker.ProcessWorkerEventHandler processWorkerEventHandler = new BackgroundWorker.ProcessWorkerEventHandler(this.ProcessWorker);
|
|
processWorkerEventHandler.BeginInvoke(argument, this.async, new SendOrPostCallback(this.CompleteWorker), null, null);
|
|
}
|
|
|
|
/// <summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.DoWork" /> event. </summary>
|
|
/// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
|
|
// Token: 0x06000379 RID: 889 RVA: 0x0000AA4C File Offset: 0x00008C4C
|
|
protected virtual void OnDoWork(DoWorkEventArgs e)
|
|
{
|
|
if (this.DoWork != null)
|
|
{
|
|
this.DoWork(this, e);
|
|
}
|
|
}
|
|
|
|
/// <summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.ProgressChanged" /> event.</summary>
|
|
/// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param>
|
|
// Token: 0x0600037A RID: 890 RVA: 0x0000AA68 File Offset: 0x00008C68
|
|
protected virtual void OnProgressChanged(ProgressChangedEventArgs e)
|
|
{
|
|
if (this.ProgressChanged != null)
|
|
{
|
|
this.ProgressChanged(this, e);
|
|
}
|
|
}
|
|
|
|
/// <summary>Raises the <see cref="E:System.ComponentModel.BackgroundWorker.RunWorkerCompleted" /> event.</summary>
|
|
/// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param>
|
|
// Token: 0x0600037B RID: 891 RVA: 0x0000AA84 File Offset: 0x00008C84
|
|
protected virtual void OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
|
|
{
|
|
if (this.RunWorkerCompleted != null)
|
|
{
|
|
this.RunWorkerCompleted(this, e);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0400011A RID: 282
|
|
private AsyncOperation async;
|
|
|
|
// Token: 0x0400011B RID: 283
|
|
private bool cancel_pending;
|
|
|
|
// Token: 0x0400011C RID: 284
|
|
private bool report_progress;
|
|
|
|
// Token: 0x0400011D RID: 285
|
|
private bool support_cancel;
|
|
|
|
// Token: 0x02000307 RID: 775
|
|
// (Invoke) Token: 0x06001BF5 RID: 7157
|
|
private delegate void ProcessWorkerEventHandler(object argument, AsyncOperation async, SendOrPostCallback callback);
|
|
}
|
|
}
|