[ToolboxBitmapAttribute(typeof(BackgroundWorker))]
[DefaultEventAttribute("DoWork")]
[HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)]
public class DevBackgroundWorker : BackgroundWorker
<ToolboxBitmapAttribute(GetType(BackgroundWorker))>
<DefaultEventAttribute("DoWork")>
<HostProtectionAttribute(SecurityAction.LinkDemand, SharedState := true)>
Public Class DevBackgroundWorker
Inherits BackgroundWorker
Dim instance As DevBackgroundWorker
[ToolboxBitmapAttribute(typeof(BackgroundWorker))]
[DefaultEventAttribute(L"DoWork")]
[HostProtectionAttribute(SecurityAction::LinkDemand, SharedState = true)]
public ref class DevBackgroundWorker : public BackgroundWorker
[<ToolboxBitmapAttribute(typeof(BackgroundWorker))>]
[<DefaultEventAttribute("DoWork")>]
[<HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)>]
type DevBackgroundWorker =
class
inherit BackgroundWorker
end
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Friend WithEvents Worker As DevBackgroundWorker
Private Sub Button_Run_Click() Handles Button_Run.Click
If (Me.Worker IsNot Nothing) Then
Select Case Me.Worker.State
Case DevBackgroundWorkerState.Running, DevBackgroundWorkerState.Paused
Me.Worker.Cancel()
Case Else
' Do Nothing.
End Select
End If
Me.Worker = New DevBackgroundWorker
Me.Worker.RunAsync()
End Sub
Private Sub Button_Pause_Click() Handles Button_Pause.Click
Me.Worker.RequestPause()
End Sub
Private Sub Button_Resume_Click() Handles Button_Resume.Click
Me.Worker.Resume()
End Sub
Private Sub Button_Cancel_Click() Handles Button_Cancel.Click
Me.Worker.Cancel()
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Handles the <see cref="DevBackgroundWorker.DoWork"/> event of the <see cref="Worker"/> instance.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="sender">
''' The source of the event.
''' </param>
'''
''' <param name="e">
''' The <see cref="DoWorkEventArgs"/> instance containing the event data.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepperBoundary>
Private Sub Worker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) _
Handles Worker.DoWork
Dim progress As Integer
Dim lock As Object = ""
SyncLock lock
For i As Integer = 0 To 100
If (Me.Worker.CancellationPending) Then ' Cancel the background operation.
e.Cancel = True
Exit For
Else
If (Me.Worker.PausePending) Then ' Pause the background operation.
Me.Worker.Pause() ' Blocking pause call.
End If
Me.DoSomething()
If Me.Worker.WorkerReportsProgress Then
progress = i
Me.Worker.ReportProgress(progress)
End If
End If
Next i
End SyncLock
If (Me.Worker.WorkerReportsProgress) AndAlso Not (Me.Worker.CancellationPending) AndAlso (progress < 100) Then
Me.Worker.ReportProgress(percentProgress:=100)
End If
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Handles the <see cref="DevBackgroundWorker.ProgressChanged"/> event of the <see cref="Worker"/> instance.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="sender">
''' The source of the event.
''' </param>
'''
''' <param name="e">
''' The <see cref="ProgressChangedEventArgs"/> instance containing the event data.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepperBoundary>
Private Sub Worker_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) _
Handles Worker.ProgressChanged
Console.WriteLine(String.Format("Background Work Progress: {00}%", e.ProgressPercentage))
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Handles the <see cref="DevBackgroundWorker.RunWorkerCompleted"/> event of the <see cref="Worker"/> instance.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="sender">
''' The source of the event.
''' </param>
'''
''' <param name="e">
''' The <see cref="RunWorkerCompletedEventArgs"/> instance containing the event data.
''' </param>
''' ----------------------------------------------------------------------------------------------------
<DebuggerStepperBoundary>
Private Sub Worker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) _
Handles Worker.RunWorkerCompleted
If (e.Cancelled) Then
Debug.WriteLine("Background work cancelled.")
ElseIf (e.Error IsNot Nothing) Then
Debug.WriteLine("Background work error.")
Else
Debug.WriteLine("Background work done.")
End If
Console.WriteLine(String.Format("State: {0}", Me.Worker.State.ToString()))
End Sub
<DebuggerStepperBoundary>
Private Sub DoSomething()
Thread.Sleep(TimeSpan.FromSeconds(1))
End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
DevBackgroundWorker | Initializes a new instance of the DevBackgroundWorker class. |
CancellationPending | Gets a value indicating whether the application has requested cancellation of a background operation. (Inherited from BackgroundWorker) |
Container | Gets the IContainer that contains the Component. (Inherited from Component) |
IsBusy | Gets a value indicating whether the BackgroundWorker is running an asynchronous operation. (Inherited from BackgroundWorker) |
PausePending | Gets a value indicating whether the application has requested pause of a background operation. |
Site | Gets or sets the ISite of the Component. (Inherited from Component) |
State | Gets the current state of a pending background operation. |
WorkerReportsProgress | Gets a value indicating whether the DevBackgroundWorker can report progress updates. |
WorkerSupportsCancellation | Gets a value indicating whether the DevBackgroundWorker supports asynchronous cancellation. |
Cancel | Requests cancellation of a pending background operation. It blocks the caller thread until the remaining background work is canceled. |
CancelAsync | Asynchronously requests cancellation of a pending background operation. |
CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject) |
Dispose | Releases all resources used by the Component. (Inherited from Component) |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
Pause | Pause a pending background operation. It blocks the caller thread until the background work is resumed. To resume the background work, call the Resume method. |
ReportProgress(Int32) | Raises the ProgressChanged event. (Inherited from BackgroundWorker) |
ReportProgress(Int32, Object) | Raises the ProgressChanged event. (Inherited from BackgroundWorker) |
RequestPause | Asynchronously requests to pause a pending background operation. To pause the background work after requesting a pause, call the Pause method. |
Resume | Resume a pending paused background operation. |
Run | Starts execution of a background operation. It blocks the caller thread until the background work is done. |
RunAsync | Asynchronously starts execution of a background operation. |
RunWorkerAsync | Starts execution of a background operation. (Inherited from BackgroundWorker) |
RunWorkerAsync(Object) | Starts execution of a background operation. (Inherited from BackgroundWorker) |
ToString | Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component) |
Disposed | Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component) |
DoWork | Occurs when RunWorkerAsync is called. (Inherited from BackgroundWorker) |
ProgressChanged | Occurs when ReportProgress(Int32) is called. (Inherited from BackgroundWorker) |
RunWorkerCompleted | Occurs when the background operation has completed, has been canceled, or has raised an exception. (Inherited from BackgroundWorker) |
CanConvertTo |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
CanConvertToT |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, an exception is thrown.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, returns the specified default value.
(Defined by ObjectExtensions) |
GetEvent |
Gets a EventInfo that match the specified event name
declared in the source Component.
(Defined by ComponentExtensions) |
GetEventHandlers |
Gets all the delegates associated to the specified event raised by the source Component.
(Defined by ComponentExtensions) |
GetEvents |
Gets all the events declared in the source Component.
(Defined by ComponentExtensions) |
GetSubscribedEvents |
Gets a list of events declared in the source Component
that are subscribed to a event-handler.
(Defined by ComponentExtensions) |
InvokeUITypeEditorT |
Invokes the default UITypeEditor to edit the specified property.
(Defined by ComponentExtensions) |
InvokeUITypeEditorT |
Invokes the default UITypeEditor to edit the specified property.
(Defined by ComponentExtensions) |
IsDisposable |
Determines whether the specified object is a disposable type
(i.e., it implements IDisposable interface).
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
ThrowIfNullTException |
Throws the specified exception if the source object is null.
(Defined by ObjectExtensions) |
TryGetEvent |
Tries to get a EventInfo that match the specified event name
declared in the source Component.
(Defined by ComponentExtensions) |