This maybe a more general threading question i'm not sure.
But I've got a WPF app that subscribes to channels and listens for messages from a redis database.
App.SubscriptionThread = new Thread(() =>
{
_redisSubscription.SubscribeToChannels("ChannelA", "ChannelB");
});
App.SubscriptionThread.Start();
Once I start this I have no idea how to stop it.
Things I've tried.
Using the
Thread.Abort
. This apparently doesn't stop it, as the thread just goes into a hang then forever (no unsubscription happens).Using the
_redisSubscription.UnSubscribeFromAllChannels()
from the UI thread. This also causes the applicaiton to go into a blocking state foreverForcefully shutdown using
Environment.Exit(0)
. This one seems to do the trick. Unfortunetly it also has the side effect of...well...shutting down my application.
How do I go about just stopping the listening, so I can connect/reconnect at will?
Am I doing it wrong by starting the SubscribeToChannels in a new thread?