如何以编程方式知道计算机上是否启用了消息队列? [英] How to know programmatically whether Message Queueing is enabled on the machine or not?

查看:76
本文介绍了如何以编程方式知道计算机上是否启用了消息队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道当我尝试创建新的MessageQueue时,如果未启用消息队列,系统将抛出InvalidOperationException.

I know that when I try to create new MessageQueue, system throws InvalidOperationException if the Message Queuing is not enabled.

但是如何以编程方式知道计算机上是否启用了消息队列? 我正在使用C#2.0&两种不同代码库中的C#4.0.

But how to know programmatically whether Message Queueing is enabled on the machine or not? I am using C# 2.0 & C# 4.0 in two different code bases.

推荐答案

您可以为此使用 System.ServiceProcess ,但是首先您需要为项目添加引用Service.ServiceProcess,您可以检索所有服务并按以下方式获取其状态:

You can use the System.ServiceProcess for this one, but first you need to add reference to your project the Service.ServiceProcess, and you can retrieve all the services and get their status like this:

List<ServiceController> services = ServiceController.GetServices().ToList();
ServiceController msQue = services.Find(o => o.ServiceName == "MSMQ");
if (msQue != null) {
    if (msQue.Status == ServiceControllerStatus.Running) { 
        // It is running.
    }
} else { // Not installed? }

这篇关于如何以编程方式知道计算机上是否启用了消息队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆