windows窗体应用程序消费RabbitMQ消息队列,只在初次运行才生效,然后控制台程序执行同一段代码却能一直生效,现在我想用winform一直监听消费端该怎么处理呢?

public Form1()
{
InitializeComponent();
用户名密码,服务器地址,端口号略...

        using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare("bj_gaojiachang", true, false, false, null);//"hello", true, false, false, null
                consumer = new EventingBasicConsumer(channel);
                channel.BasicConsume("bj_gaojiachang", true, consumer);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    File.AppendAllText(pathUrl, message + "\r\n");
                };
                Console.ReadLine();
            }
        }
    }

using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
这里不要用using 会把对象释放掉 那using去了就可以

不要写在构造函数里,可以写在一个线程里
然后调用
Application.Run(); 让程序保持住。