Esempio gestione PubSub in Redis
This commit is contained in:
+21
-5
@@ -25,6 +25,24 @@ namespace TestBench
|
||||
myInitComponent();
|
||||
}
|
||||
|
||||
private delegate void SetTextCallback(string text);
|
||||
|
||||
private void SetText(string text)
|
||||
{
|
||||
// InvokeRequired required compares the thread ID of the
|
||||
// calling thread to the thread ID of the creating thread.
|
||||
// If these threads are different, it returns true.
|
||||
if (this.lblChannelReceive.InvokeRequired)
|
||||
{
|
||||
SetTextCallback d = new SetTextCallback(SetText);
|
||||
this.Invoke(d, new object[] { text });
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lblChannelReceive.Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
private void myInitComponent()
|
||||
{
|
||||
// imposto folders
|
||||
@@ -40,11 +58,9 @@ namespace TestBench
|
||||
myRedis = new SteamWare.IO.Redis();
|
||||
subscriber = myRedis.RedPubSub;
|
||||
// fix redis channel subscription
|
||||
subscriber.Subscribe("TestChannel").OnMessage(async channelMessage =>
|
||||
subscriber.Subscribe("TestChannel").OnMessage(channelMessage =>
|
||||
{
|
||||
await Task.Delay(10);
|
||||
//Console.WriteLine((string)channelMessage.Message);
|
||||
lblChannelReceive.Text = (string)channelMessage.Message;
|
||||
SetText((string)channelMessage.Message);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -57,8 +73,8 @@ namespace TestBench
|
||||
subscriber.Publish("TestChannel", $"{DateTime.Now} | {txtChannelSend.Text}");
|
||||
// reset
|
||||
txtChannelSend.Text = "";
|
||||
//MessageBox.Show("ENTER has been pressed!");
|
||||
}
|
||||
MessageBox.Show("ENTER has been pressed!");
|
||||
//// ESC
|
||||
//else if (e.KeyChar == (char)27)
|
||||
// this.Close();
|
||||
|
||||
Reference in New Issue
Block a user