{"id":262,"date":"2009-12-04T15:32:00","date_gmt":"2009-12-04T22:32:00","guid":{"rendered":"http:\/\/cknotes.com\/?p=262"},"modified":"2015-11-08T11:43:32","modified_gmt":"2015-11-08T18:43:32","slug":"aborting-in-c","status":"publish","type":"post","link":"https:\/\/cknotes.com\/aborting-in-c\/","title":{"rendered":"Aborting in C++"},"content":{"rendered":"<p>The technique for aborting any time-consuming Chilkat C++ method call follows this recipe:<\/p>\n<ol>\n<li>Declare your own class that derives from the appropriate Chilkat progress monitoring class.&nbsp; For CkMailMan it is CkMailManProgress (as shown below).&nbsp; For other Chilkat classes it is CkHttpProgress, CkFtpProgress, CkImapProgress, CkZipProgress, etc.<\/li>\n<li>Create an implementation for the AbortCheck method.&nbsp; This will override the default implementation from the base class.&nbsp; (The default implementation simply does nothing.)<\/li>\n<li>The AbortCheck method is called periodically according to the value of the HeartbeatMs property.&nbsp; The default value of HeartbeatMs is 0, which indicate that no AbortCheck events should be called.&nbsp; Set HeartbeatMs to a non-zero value (in milliseconds) to enable the AbortCheck callbacks.&nbsp; Do this by calling put_HeartbeatMs(someValue)&nbsp; as shown below.<\/li>\n<li>Whenever your application wishes to abort an operation in progress (SMTP, POP3, IMAP, Zip, FTP, etc.), set the <em>abort<\/em> boolean argument of AbortCheck to true.<\/li>\n<li>Don&#8217;t forget to hookup your event monitoring class by calling the SetProgressCallback method.&nbsp; (See the code example below.)&nbsp; In some classes, such as for CkImap, the way to hookup the event class is via the put_EventCallbackObject function.&nbsp; Please review the .h file for details.<\/li>\n<\/ol>\n<pre>#include &lt;CkMailManProgress.h>\r\n\r\nclass MyMailProgress : public CkMailManProgress\r\n    {\r\n    public:\r\n\tMyMailProgress(void) { }\r\n\tvirtual ~MyMailProgress(void) { }\r\n\r\n\t\/\/ Override the AbortCheck method (which is a virtual method in CkMailProgress)\r\n\t\/\/ Called periodically according to the value of the HeartbeatMs property.\r\n\tvoid AbortCheck(bool *abort)\r\n\t    {\r\n\t    printf(\"AbortCheck!\\n\");\r\n\r\n\t    \/\/ If your application wishes to abort the email sending\/receiving operation,\r\n\t    \/\/ set the abort boolean like this:\r\n\t    *abort = true;\r\n\t    }\r\n\r\n        \/\/ Percentage completion events may also be overridden to abort time-consuming operations.\r\n\tvoid SendPercentDone(long pctDone, bool *abort) \r\n\t    { \r\n\t    printf(\"SendPercentDone: %d percent\\n\",pctDone);\r\n\t    }\r\n\tvoid ReadPercentDone(long pctDone, bool *abort) \r\n\t    { \r\n\t    printf(\"ReadPercentDone: %d percent\\n\",pctDone);\r\n\t    }\r\n\r\n    };\r\n\r\nvoid AbortCheckDemo(void)\r\n    {\r\n    CkMailMan mailman;\r\n    bool success;\r\n    success = mailman.UnlockComponent(\"30-day trial\");\r\n    if (success != true)\r\n\t{\r\n        printf(\"%s\\n\",mailman.lastErrorText());\r\n        return;\r\n\t}\r\n\r\n    \/\/ Set the HeartbeatMs property so that AbortCheck is called once every 80 milliseconds.\r\n    mailman.put_HeartbeatMs(80);\r\n\r\n    MyMailProgress myProgress;\r\n    mailman.SetProgressCallback(&amp;myProgress);\r\n\r\n    CkEmail email;\r\n    \/\/ ...\r\n    \/\/ ...\r\n\r\n    \/\/ The AbortCheck event is called periodically while SendEmail is in progress..\r\n    \/\/ (Note: In some cases, including here, a percent-done event is also called, and it will have an \"abort\"\r\n    \/\/ boolean argument that may be set to \"true\" to force an abort.\r\n    \/\/ If the percent-done callbacks happen more frequently than the HeartbeatMs setting, then \r\n    \/\/ the AbortCheck events may not be fired at all.)\r\n    success = mailman.SendEmail(email);\r\n    if (success != true)\r\n\t{\r\n        printf(\"%s\\n\",mailman.lastErrorText());\r\n        return;\r\n\t}\r\n\r\n    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The technique for aborting any time-consuming Chilkat C++ method call follows this recipe: Declare your own class that derives from the appropriate Chilkat progress monitoring class.&nbsp; For CkMailMan it is CkMailManProgress (as shown below).&nbsp; For other Chilkat classes it is CkHttpProgress, CkFtpProgress, CkImapProgress, CkZipProgress, etc. Create an implementation for the AbortCheck method.&nbsp; This will override [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[260,448,443],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-abort","tag-c","tag-events"],"_links":{"self":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":1,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/262\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cknotes.com\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}