Subscribe(String,TimeSpan,Boolean,Action<PubSubMessage>) Method
- Last UpdatedApr 08, 2026
- 2 minute read
public IPubSubSubscription Subscribe(
string topic,
TimeSpan timeout,
bool withIntegrity,
Action<PubSubMessage> callback
)
public:
IPubSubSubscription^ Subscribe(
String^ topic,
TimeSpan timeout,
bool withIntegrity,
Action<PubSubMessage^>^ callback
)
Parameters
- topic
- The topic string to subscribe to.
- timeout
- The receive message timeout.
- withIntegrity
- Indicates whether or not integrity updates have been requested.
- callback
- The callback to be invoked when a new PubSub message has been received.
| Exception | Description |
|---|---|
| PubSubConnection.BadCallException | A previous call to blocking subscribe was made. |
| PubSubConnection.BadTopicException | The topic string is invalid. |
| PubSubConnection.NotInitException | The initialize was not called. |
| PubSubConnection.NoMemException | The memory allocation failed. |
Note: This method is capable of dealing with the serialization required by System.Windows.Forms.Control and all descendants. That is, if the subscriber is a Form Control, then the System.Windows.Forms.Control.Invoke(System.Delegate,System.Object[]) method will be used to execute the callback in a serialized manner. If the Subscriber is not a Forms Control, then the callback is made preemptively.
If the specified timeout is equal to System.Threading.Timeout.InfiniteTimeSpan, then the PubSub subscription will remain active as long as the PubSub connection status is PubSubStatus.PS_OK. However, if the specified timeout is a non-infinite value, the PubSub subscription will be canceled if no PubSub message has been received within the specified time window and a final callback with a PubSubStatus.PS_TIMEOUT will be triggered.
using (var connection = new PubSubConnection())
using (var subscription = connection.Subscribe("mySystem.MyTopic", TimeSpan.FromSeconds(30), withIntegrity: true, callback: (message) => { /* Process Message */ }))
{
// Wait for shutdown condition.
}