Sample code for 30+ languages & platforms
SQL Server

Monitor and Cancel a Running DKIM Operation

See more DKIM / DomainKey Examples

Demonstrates the Chilkat Dkim.HeartbeatMs and Dkim.AbortCurrent properties, which monitor and cancel a long-running operation such as a DNS public-key lookup. HeartbeatMs sets how often an AbortCheck event fires, and AbortCurrent requests cancellation.

Background: Most Dkim work is instant, but anything touching DNS can stall on a slow or unresponsive server. HeartbeatMs makes the object emit a periodic AbortCheck callback during such calls so an application stays responsive and can show progress, and AbortCurrent — set from that callback or from another thread — breaks a blocked synchronous call out early. Together they turn an otherwise uninterruptible operation into a cancellable one.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Demonstrates the Dkim properties HeartbeatMs and AbortCurrent, which monitor and cancel a
    --  long-running operation such as a DNS public-key lookup.

    DECLARE @dkim int
    EXEC @hr = sp_OACreate 'Chilkat.Dkim', @dkim OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Fire an AbortCheck event callback every 100 ms during method calls.  In programming languages
    --  where Chilkat supports event callbacks, the callback can request cancellation.
    EXEC sp_OASetProperty @dkim, 'HeartbeatMs', 100

    --  AbortCurrent may be set to 1 to request cancellation of a running operation.  It is
    --  typically set from another thread, or from within an AbortCheck callback.  Setting it 0
    --  here ensures the operation is not pre-emptively aborted.
    EXEC sp_OASetProperty @dkim, 'AbortCurrent', 0

    --  PrefetchPublicKey performs a synchronous DNS lookup, which HeartbeatMs monitors and
    --  AbortCurrent can cancel.
    EXEC sp_OAMethod @dkim, 'PrefetchPublicKey', @success OUT, 'myselector', 'example.com'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @dkim, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @dkim
        RETURN
      END

    PRINT 'Public key prefetched.'

    EXEC @hr = sp_OADestroy @dkim


END
GO