Class DocumentLoadingArgs

Class DocumentLoadingArgs

Namespace: Aspose.Words.Loading
Assembly: Aspose.Words.dll (25.12.0)

An argument passed into Aspose.Words.Loading.IDocumentLoadingCallback.Notify(Aspose.Words.Loading.DocumentLoadingArgs).

To learn more, visit the Specify Load Options documentation article.

public sealed class DocumentLoadingArgs

Inheritance

object DocumentLoadingArgs

Inherited Members

object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Shows how to notify the user if document loading exceeded expected loading time.

public void ProgressCallback()
                                                                                           {
                                                                                               LoadingProgressCallback progressCallback = new LoadingProgressCallback();

                                                                                               LoadOptions loadOptions = new LoadOptions { ProgressCallback = progressCallback };

                                                                                               try
                                                                                               {
                                                                                                   Document doc = new Document(MyDir + "Big document.docx", loadOptions);
                                                                                               }
                                                                                               catch (OperationCanceledException exception)
                                                                                               {
                                                                                                   Console.WriteLine(exception.Message);

                                                                                                   // Handle loading duration issue.
                                                                                               }
                                                                                           }

                                                                                           /// <summary>
                                                                                           /// Cancel a document loading after the "MaxDuration" seconds.
                                                                                           /// </summary>
                                                                                           public class LoadingProgressCallback : IDocumentLoadingCallback
                                                                                           {
                                                                                               /// <summary>
                                                                                               /// Ctr.
                                                                                               /// </summary>
                                                                                               public LoadingProgressCallback()
                                                                                               {
                                                                                                   mLoadingStartedAt = DateTime.Now;
                                                                                               }

                                                                                               /// <summary>
                                                                                               /// Callback method which called during document loading.
                                                                                               /// </summary>
                                                                                               /// <param name="args">Loading arguments.</param>
                                                                                               public void Notify(DocumentLoadingArgs args)
                                                                                               {
                                                                                                   DateTime canceledAt = DateTime.Now;
                                                                                                   double ellapsedSeconds = (canceledAt - mLoadingStartedAt).TotalSeconds;

                                                                                                   if (ellapsedSeconds > MaxDuration)
                                                                                                       throw new OperationCanceledException($"EstimatedProgress = {args.EstimatedProgress}; CanceledAt = {canceledAt}");
                                                                                               }

                                                                                               /// <summary>
                                                                                               /// Date and time when document loading is started.
                                                                                               /// </summary>
                                                                                               private readonly DateTime mLoadingStartedAt;

                                                                                               /// <summary>
                                                                                               /// Maximum allowed duration in sec.
                                                                                               /// </summary>
                                                                                               private const double MaxDuration = 0.5;
                                                                                           }

Properties

EstimatedProgress

Overall estimated percentage progress.

public double EstimatedProgress { get; }

Property Value

double

Examples

Shows how to notify the user if document loading exceeded expected loading time.

public void ProgressCallback()
                                                                                           {
                                                                                               LoadingProgressCallback progressCallback = new LoadingProgressCallback();

                                                                                               LoadOptions loadOptions = new LoadOptions { ProgressCallback = progressCallback };

                                                                                               try
                                                                                               {
                                                                                                   Document doc = new Document(MyDir + "Big document.docx", loadOptions);
                                                                                               }
                                                                                               catch (OperationCanceledException exception)
                                                                                               {
                                                                                                   Console.WriteLine(exception.Message);

                                                                                                   // Handle loading duration issue.
                                                                                               }
                                                                                           }

                                                                                           /// <summary>
                                                                                           /// Cancel a document loading after the "MaxDuration" seconds.
                                                                                           /// </summary>
                                                                                           public class LoadingProgressCallback : IDocumentLoadingCallback
                                                                                           {
                                                                                               /// <summary>
                                                                                               /// Ctr.
                                                                                               /// </summary>
                                                                                               public LoadingProgressCallback()
                                                                                               {
                                                                                                   mLoadingStartedAt = DateTime.Now;
                                                                                               }

                                                                                               /// <summary>
                                                                                               /// Callback method which called during document loading.
                                                                                               /// </summary>
                                                                                               /// <param name="args">Loading arguments.</param>
                                                                                               public void Notify(DocumentLoadingArgs args)
                                                                                               {
                                                                                                   DateTime canceledAt = DateTime.Now;
                                                                                                   double ellapsedSeconds = (canceledAt - mLoadingStartedAt).TotalSeconds;

                                                                                                   if (ellapsedSeconds > MaxDuration)
                                                                                                       throw new OperationCanceledException($"EstimatedProgress = {args.EstimatedProgress}; CanceledAt = {canceledAt}");
                                                                                               }

                                                                                               /// <summary>
                                                                                               /// Date and time when document loading is started.
                                                                                               /// </summary>
                                                                                               private readonly DateTime mLoadingStartedAt;

                                                                                               /// <summary>
                                                                                               /// Maximum allowed duration in sec.
                                                                                               /// </summary>
                                                                                               private const double MaxDuration = 0.5;
                                                                                           }
 English