Skip to content

Publish in the Future

The example demonstrates scheduling a message to be delivered on January 1st, 2030 at 00:00 Central time. The message is published into the demo channel:

DeliveryOptions deliveryOptions = new DeliveryOptions();

DateTime publishDate = new DateTime( TimeSpan.FromMilliseconds( 1893477600000 ).Ticks );
deliveryOptions.PublishAt = publishDate;

AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>(
   messageStatus =>
   {
     Console.WriteLine( $"message has been published {messageStatus.MessageId}"); 
   },
   fault =>
   {
     Console.WriteLine( $"error {fault.Message}");
   } 
);

Backendless.Messaging.Publish( "demo",
                               "Happy New Year!",
                               null, // this is null since a PublishOptions object is not provided
                               // see the "Conditional Pub/Sub" section for an example of how
                               // to use the PublishOptions object for this argument
                               deliveryOptions,
                               callback );