Signature class supports cancellation for each of document processing (Sign, Verify, Search). The process cancellation happens over setting property Cancel of ProcessProgressEventArgs property in proper event handler.
for Sign process this flag should be set to true in handler of SignProgress event. This event occurs each time on signing each signature was completed.
for Verify process this flag should be set to true in handler of VerifyProgress event. This event occurs each time on verifying document page.
for Search process this flag should be set to true in handler of SearchProgress event. This event occurs each time on searching document page per each options.
Cancel signing process
Here are the steps to provide cancellation for signing process with GroupDocs.Signature:
Define SignProgress event handler delegates to conditionally cancel the process.
Create new instance of Signature class and pass source document path or stream as a constructor parameter.
Subscribe for SignProgress event with proper handler method.
Call Sign method of Signature class instance and pass signature options in it.
privatestaticvoidOnSignProgress(Signaturesender,ProcessProgressEventArgsargs){// check if process takes more than 1 second (1000 milliseconds) processing cancellationif(args.Ticks>1000){args.Cancel=true;Console.WriteLine("Sign progress was cancelled. Time spent {0} mlsec",args.Ticks);}}/// <summary>/// Sign document with text signature applying specific options/// </summary>publicstaticvoidRun(){using(Signaturesignature=newSignature("sample.docx")){signature.SignProgress+=OnSignProgress;TextSignOptionsoptions=newTextSignOptions("John Smith"){// ...};// sign document to filesignature.Sign("signedSample",options);}}
Cancel verification process
Here are the steps to provide cancellation for verification process with GroupDocs.Signature:
Define VerifyProgress event handler delegates to conditionally cancel the process.
Create new instance of Signature class and pass source document path or stream as a constructor parameter.
Subscribe for VerifyProgress event with proper handler method.
Call Verify method of Signature class instance and pass verification options in it.
privatestaticvoidOnVerifyProgress(Signaturesender,ProcessProgressEventArgsargs){// check if process takes more than 1 second (1000 milliseconds) processing cancellationif(args.Ticks>1000){args.Cancel=true;Console.WriteLine("Sign progress was cancelled. Time spent {0} mlsec",args.Ticks);}}publicstaticvoidRun(){using(Signaturesignature=newSignature("SignedSample.pdf")){signature.VerifyProgress+=OnVerifyProgress;TextVerifyOptionsoptions=newTextVerifyOptions("John Smith"){// ...};// sign document to fileVerificationResultresult=signature.Verify(options);}}
Cancel search process
Here are the steps to provide cancellation of searching process with GroupDocs.Signature:
Define SearchProgress event handler delegates to conditionally cancel the process.
Create new instance of Signature class and pass source document path or stream as a constructor parameter.
Subscribe for SearchProgress event with proper handler method.
Call Search method of Signature class instance and pass search options in it.
privatestaticvoidOnSearchProgress(Signaturesender,ProcessProgressEventArgsargs){// check if process takes more than 1 second (1000 milliseconds) processing cancellationif(args.Ticks>1000){args.Cancel=true;Console.WriteLine("Sign progress was cancelled. Time spent {0} mlsec",args.Ticks);}}publicstaticvoidRun(){using(Signaturesignature=newSignature("sampleSigned.pdf")){signature.SearchProgress+=OnSearchProgress;QrCodeSearchOptionsoptions=newQrCodeSearchOptions(QrCodeTypes.QR){// ...};// search for signatures in documentList<QrCodeSignature>signatures=signature.Search<QrCodeSignature>(options);Console.WriteLine("\nSource document contains following signatures.");foreach(varQrCodeSignatureinsignatures){Console.WriteLine("QRCode signature found at page {0} with type {1} and text {2}",QrCodeSignature.PageNumber,QrCodeSignature.EncodeType,QrCodeSignature.Text);}}}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: