public class BackgroundCalculation extends SwingWorker<Object,Void> implements ITrackCalculationProgress
CalculationContext
for the new thread by copying
the context of the thread that initiates the background computation.
ITrackCalculationProgress
interface so that it
can be passed directly to long running operations to support progress reporting
and cancellation.
AsyncWaitHandle
(get
) property.
It returns a WaitHandle
that is set to signaled when the DoWork
(add
/ remove
)
event handler completes.
SwingWorker.StateValue
Constructor and Description |
---|
BackgroundCalculation()
Initializes a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addDoWork(DoWorkEventHandler value)
Adds a handler for an event that occurs when
BackgroundCalculation.runWorkerAsync() is called. |
void |
addProgressChanged(ProgressChangedEventHandler value)
Adds a handler for an event that occurs when
BackgroundCalculation.reportProgress(int, java.lang.Object) is called. |
void |
addRunWorkerCompleted(RunWorkerCompletedEventHandler value)
Adds a handler for an event that occurs when the background operation has completed,
been canceled, or raised an exception.
|
void |
cancelAsync()
Requests cancellation of a pending background operation.
|
void |
captureCalculationContext()
Captures the calculation context of the calling thread.
|
protected Object |
doInBackground() |
protected void |
done() |
ManualResetEvent |
getAsyncWaitHandle()
Gets a
WaitHandle that is used to wait for the operation to complete. |
boolean |
getCancellationPending()
Gets a value indicating whether the application has requested cancellation of
a background operation.
|
boolean |
getIsBusy()
Gets a value indicating whether this instance is running an asynchronous operation.
|
boolean |
getWorkerReportsProgress()
Gets a value indicating whether this instance can report progress updates.
|
boolean |
getWorkerSupportsCancellation()
Gets a value indicating whether this instance supports asynchronous cancellation.
|
void |
removeDoWork(DoWorkEventHandler value)
Removes a handler for an event that occurs when
BackgroundCalculation.runWorkerAsync() is called. |
void |
removeProgressChanged(ProgressChangedEventHandler value)
Removes a handler for an event that occurs when
BackgroundCalculation.reportProgress(int, java.lang.Object) is called. |
void |
removeRunWorkerCompleted(RunWorkerCompletedEventHandler value)
Removes a handler for an event that occurs when the background operation has completed,
been canceled, or raised an exception.
|
void |
reportProgress(int percentProgress,
Object additionalInformation)
|
void |
runWorkerAsync()
Starts execution of a background operation.
|
void |
runWorkerAsync(Object argument)
Starts execution of a background operation.
|
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, process, publish, removePropertyChangeListener, run, setProgress
public BackgroundCalculation()
CalculationContext
from the
thread constructing the new instance in order to pass the context to the new thread when
BackgroundCalculation.runWorkerAsync()
is called. To capture the context again later, call
BackgroundCalculation.captureCalculationContext()
.public void captureCalculationContext()
BackgroundCalculation.runWorkerAsync()
is called. This method cannot
be called after BackgroundCalculation.runWorkerAsync()
.IllegalStateException
- Thrown when the background computation has already been started. The calculation context
cannot be captured after this point.public ManualResetEvent getAsyncWaitHandle()
WaitHandle
that is used to wait for the operation to complete.
When the DoWork
(add
/ remove
)
event handler has finished, this event will be signaled.public boolean getCancellationPending()
getCancellationPending
in interface ITrackCalculationProgress
public void cancelAsync()
public void runWorkerAsync()
public void runWorkerAsync(Object argument)
protected Object doInBackground()
doInBackground
in class SwingWorker<Object,Void>
protected void done()
done
in class SwingWorker<Object,Void>
public void reportProgress(int percentProgress, Object additionalInformation)
reportProgress
in interface ITrackCalculationProgress
percentProgress
- The percentage, from 0 to 100, of the background operation that is complete.additionalInformation
- The state object passed to BackgroundCalculation.runWorkerAsync()
.public boolean getIsBusy()
public boolean getWorkerReportsProgress()
public boolean getWorkerSupportsCancellation()
public void addDoWork(DoWorkEventHandler value)
BackgroundCalculation.runWorkerAsync()
is called.value
- The handler.public void removeDoWork(DoWorkEventHandler value)
BackgroundCalculation.runWorkerAsync()
is called.value
- The handler to remove.public void addProgressChanged(ProgressChangedEventHandler value)
BackgroundCalculation.reportProgress(int, java.lang.Object)
is called.value
- The handler.public void removeProgressChanged(ProgressChangedEventHandler value)
BackgroundCalculation.reportProgress(int, java.lang.Object)
is called.value
- The handler to remove.public void addRunWorkerCompleted(RunWorkerCompletedEventHandler value)
value
- The handler.public void removeRunWorkerCompleted(RunWorkerCompletedEventHandler value)
value
- The handler to remove.