The main entry point for using Selena.
public class SelenaChannel : IDisposablepublic SelenaChannel(string channelName)
public SelenaChannel(SelenaConfig config)Config- Gets the channel configurationIsStarted- Gets whether the channel is started and listening
public void Start()
public void Stop()
public void Dispose()public bool SendMessage(string text, int messageType = 0)
public Task<bool> SendMessageAsync(string text, int messageType = 0)
public bool SendBytes(byte[] data, int messageType = 0)
public Task<bool> SendBytesAsync(byte[] data, int messageType = 0)
public bool SendObject<T>(T obj, int messageType = 0)
public Task<bool> SendObjectAsync<T>(T obj, int messageType = 0)public Message? ReceiveMessage(TimeSpan timeout)
public Task<Message?> ReceiveMessageAsync(TimeSpan timeout)public event EventHandler<MessageReceivedEventArgs>? MessageReceivedpublic ChannelStatistics GetStatistics()
public void ClearBuffer()
public Task<int> BroadcastMessageAsync(string text, int count, int messageType = 0, int delayMs = 10)Configuration for a Selena channel.
public class SelenaConfig| Property | Type | Default | Description |
|---|---|---|---|
ChannelName |
string | Required | Unique identifier for the channel |
BufferSize |
int | 1048576 (1MB) | Size of the memory-mapped file buffer in bytes |
OverflowStrategy |
OverflowStrategy | Overwrite | Strategy when buffer is full |
ScopeMode |
ScopeMode | Local | Windows IPC object scope |
PollingInterval |
int | 10 | Polling interval in milliseconds (Unix only) |
MaxWaitTime |
int | 5000 | Maximum wait time for blocking operations |
EnableJsonLogging |
bool | false | Enable JSON debugging output |
public void Validate()Represents a message for IPC.
public class MessageHeader- Message metadata (MessageHeader struct)Payload- Message data as byte array
public DateTime GetTimestamp()
public int GetTotalSize()
public bool IsValid()Message metadata structure.
public struct MessageHeaderTotalLength- Total message size including headerPayloadLength- Size of payload in bytesMessageType- User-defined message type identifierTimestamp- UTC timestamp in ticksReserved- Reserved for future use
Event arguments for message received events.
public class MessageReceivedEventArgs : EventArgsMessage- The received messageChannelName- Name of the channelReceivedTime- Local receive timestamp
public string GetMessageText()
public T? GetMessageObject<T>()
public TimeSpan GetLatency()Runtime statistics for a channel.
public class ChannelStatisticsChannelName- Name of the channelBufferSize- Total buffer sizeAvailableData- Bytes available to readIsStarted- Whether channel is active
public enum OverflowStrategy
{
Overwrite, // Overwrite oldest messages
Block // Block until space available
}public enum ScopeMode
{
Local, // User session scope (default)
Global // System-wide scope (requires admin on Windows)
}// Sender
using var sender = new SelenaChannel("MyChannel");
await sender.SendMessageAsync("Hello!");
// Receiver
using var receiver = new SelenaChannel("MyChannel");
receiver.MessageReceived += (s, e) =>
{
Console.WriteLine(e.GetMessageText());
};
receiver.Start();public class MyData
{
public int Id { get; set; }
public string Name { get; set; }
}
// Send
var data = new MyData { Id = 1, Name = "Test" };
await channel.SendObjectAsync(data, messageType: 100);
// Receive
channel.MessageReceived += (s, e) =>
{
if (e.Message.Header.MessageType == 100)
{
var data = e.GetMessageObject<MyData>();
Console.WriteLine($"{data.Id}: {data.Name}");
}
};var config = new SelenaConfig
{
ChannelName = "HighPerf",
BufferSize = 50 * 1024 * 1024, // 50MB
OverflowStrategy = OverflowStrategy.Overwrite,
PollingInterval = 1, // 1ms for minimal latency on Unix
ScopeMode = ScopeMode.Local
};
using var channel = new SelenaChannel(config);- All public methods are thread-safe
- Multiple threads can send messages concurrently
- Message reception is handled on a dedicated thread
- Event handlers are invoked asynchronously
- Methods return
boolfor success/failure ObjectDisposedExceptionthrown when using disposed channelArgumentExceptionfor invalid configuration- Automatic recovery from transient failures
- Always dispose channels when done
- Use
Localscope unless cross-session needed - Size buffers appropriately for your message volume
- Use message types to distinguish different payloads
- Handle
MessageReceivedevents quickly - Validate received objects before use