Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

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

    CkDkim dkim = new CkDkim();

    //  Fire an AbortCheck event callback every 100 ms during method calls.  In programming languages
    //  where Chilkat supports event callbacks, the callback can request cancellation.
    dkim.put_HeartbeatMs(100);

    //  AbortCurrent may be set to true to request cancellation of a running operation.  It is
    //  typically set from another thread, or from within an AbortCheck callback.  Setting it false
    //  here ensures the operation is not pre-emptively aborted.
    dkim.put_AbortCurrent(false);

    //  PrefetchPublicKey performs a synchronous DNS lookup, which HeartbeatMs monitors and
    //  AbortCurrent can cancel.
    success = dkim.PrefetchPublicKey("myselector","example.com");
    if (success == false) {
        Log.i(TAG, dkim.lastErrorText());
        return;
        }

    Log.i(TAG, "Public key prefetched.");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}