Class OperationFeedback
Use this class when you want to provide feedback during time-consuming operations or if you want the user to be able to abort an operation.
Inheritance
Implements
Namespace: Syncfusion.Windows.ComponentModel
Assembly: Syncfusion.GridCommon.WPF.dll
Syntax
public sealed class OperationFeedback : Object, IDisposable
Remarks
You need to implement IOperationFeedbackProvider in your class.
// interface IOperationFeedbackProvider
public event OperationFeedbackEventHandler OperationFeedback;
Stack feedbackStack = new Stack();
void IOperationFeedbackProvider.RaiseOperationFeedbackEvent(OperationFeedbackEventArgs e)
{
if (OperationFeedback != null)
OperationFeedback(this, e);
}
Stack IOperationFeedbackProvider.FeedbackStack
{
get { return feedbackStack; }
}
When you implement an operation that you want to be cancellable or where you want to show feedback (e.g. display percentage in status bar) you do this by creating an OperationFeedback object inside a using statement.
Example:
using (OperationFeedback op = new OperationFeedback(this))
{
op.Name = "Cell";
op.Description = "Command Description";
op.AllowCancel = true;
op.AllowNestedProgress = true;
op.AllowNestedFeedback = false;
while (n++ != 100)
{
if (op.ShouldCancel())
return;
op.PercentComplete = n;
}
}
It is also supported in nest operations in case your method calls other routines that also use OperationFeedback. AllowNestedProgress will disable OperationFeedback and OperationProgress / ShouldCancel in nested routines. AllowNestedFeedback will simply prohibit changing the description. But the object will still fire OperationProgress events.
A sample for a consumer is the DelayedWaitCursor class. You can assign a DelayedWaitCursor to a grid table. The DelayedWaitCursor object will listen to OperationFeedback events and automatically change the cursor to a wait cursor if operations take more time.
Constructors
OperationFeedback(IOperationFeedbackProvider)
Initializes a new OperationFeedback object and pushes the object onto the providers feedback stack.
Declaration
public OperationFeedback(IOperationFeedbackProvider feedback)
Parameters
Type | Name | Description |
---|---|---|
IOperationFeedbackProvider | feedback | Component that implements IOperationFeedbackProvider. |
Properties
AllowCancel
Indicates whether cancelling the current operation is enabled / disabled.
Declaration
public bool AllowCancel { get; set; }
Property Value
Type |
---|
System.Boolean |
AllowNestedFeedback
Indicates whether percentage display and description for nested operations are enabled / disabled.
Declaration
public bool AllowNestedFeedback { get; set; }
Property Value
Type |
---|
System.Boolean |
AllowNestedProgress
Indicates whether nested operations are enabled / disabled.
Declaration
public bool AllowNestedProgress { get; set; }
Property Value
Type |
---|
System.Boolean |
AllowRollback
Indicates whether rolling back (undoing) the current operation is enabled / disabled.
Declaration
public bool AllowRollback { get; set; }
Property Value
Type |
---|
System.Boolean |
Counter
Returns the number of counts of calls to Progress.
Declaration
public int Counter { get; }
Property Value
Type |
---|
System.Int32 |
Description
Gets / sets the description of the operation. Use localized string (SR.GetString("...")) if necessary.
Declaration
public string Description { get; set; }
Property Value
Type |
---|
System.String |
IsNested
Indicate whether this operation is nested inside another operation.
Declaration
public bool IsNested { get; }
Property Value
Type |
---|
System.Boolean |
Name
Gets / sets the short name of the operation.
Declaration
public string Name { get; set; }
Property Value
Type |
---|
System.String |
PercentComplete
Gets / sets the progress in percentage for the current operation.
Declaration
public int PercentComplete { get; set; }
Property Value
Type |
---|
System.Int32 |
Rollback
Indicates whether the canceled operation should be rolled back.
Declaration
public bool Rollback { get; set; }
Property Value
Type |
---|
System.Boolean |
RollbackConfirmed
Returns False.
Declaration
public bool RollbackConfirmed { get; }
Property Value
Type |
---|
System.Boolean |
SeriesCount
Gets / sets the number of series if you have a series of nested operations.
Declaration
public int SeriesCount { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
If you know the number of operations in advance, you should specify this value. This allows OperationFeedback to adjust the percentage display to reflect the percentage in the overall operation. If you have two operations, the first operation will show percentage from 0 to 50 and the second from 51 to 100. In the original program code for these operations, you can keep your original calculations (setting percentage from 0 to 100). OperationFeedback simply divides the percentage by SeriesCount when it fires the Progress event.
ShouldCallProgress
Indicates whether calls to Progress or ShouldCancel have any effect.
Declaration
public bool ShouldCallProgress { get; }
Property Value
Type |
---|
System.Boolean |
ShouldCancel
Indicates whether the user wants to abort the operation. ShouldCancel will call Progress.
Declaration
public bool ShouldCancel { get; }
Property Value
Type |
---|
System.Boolean |
ShouldShowFeedback
Indicates whether the percent complete and description should be shown or discarded for this operation.
Declaration
public bool ShouldShowFeedback { get; }
Property Value
Type |
---|
System.Boolean |
Ticks
Returns the number of ticks elapsed since the operation was started.
Declaration
public int Ticks { get; }
Property Value
Type |
---|
System.Int32 |
Methods
Close()
Call this method to signal the end of the operation. If you do not explicitly call this routine it will be called automatically when you are using the "using" statement in C# and / or when Dispose is called.
Declaration
public void Close()
Progress()
Call this method inside a loop from your method that implements the operation.
Declaration
public void Progress()
Start()
Call this method to signal the start of the operation. If you do not explicitly call this routine, it will be called automatically the first time Progress or ShouldCancel is called.
Declaration
public void Start()