hi, i have a class like below which i include in my winform
application.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using ServiceStack.Redis;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestRedisPubSub
{
public class RedisEx : IDisposable
{
private readonly IRedisClient redisClient;
private readonly IRedisSubscription subscription;
private readonly TextBox log;
public RedisEx(IRedisClientsManager manager, ref TextBox elog)
{
redisClient = manager.GetClient();
subscription = redisClient.CreateSubscription();
log = elog;
}
public void Start()
{
Task.Factory.StartNew(() =>
{
subscription.OnSubscribe = channel =>
{
log.Parent.Invoke(new Action(() =>
{
log.AppendText(string.Format("Subscribed to
{0} \r\n", channel));
}));
};
subscription.OnUnSubscribe = channel =>
{
log.Parent.Invoke(new Action(() =>
{
log.AppendText(string.Format("UnSubscribed to
{0} \r\n", channel));
}));
};
subscription.OnMessage = (channel, msg) =>
{
log.Parent.Invoke(new Action(() =>
{
log.AppendText(string.Format("Channel: {0}.
Message: {1} \r\n", channel, msg));
}));
};
});
}
public void Subscribe(string channel)
{
Task.Factory.StartNew(() =>
{
subscription.SubscribeToChannels(channel);
});
}
public void UnSubscribe(string channel)
{
Task.Factory.StartNew(() =>
{
subscription.UnSubscribeFromChannels(channel);
});
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (redisClient != null)
redisClient.Dispose();
if (subscription != null)
subscription.Dispose();
if (log != null)
log.Dispose();
}
}
~RedisEx()
{
Dispose(false);
}
}
}
[/code]
can you help me why sometimes i have Unresponsive Error when i close
the winform application? how to do the best way to handling redis
object dispossing in my case? i know you gave me an example in here
already:
[code]
https://github.com/ServiceStack/ServiceStack.Redis/wiki/RedisPubSub
[/code]
but is not enough for dinamic pub and sub i think.
thank you.
greeting from indonesia,
heri