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

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

问题描述

我知道,当我尝试创建新的 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安培;下在两个不同的code碱基#4.0。

But how to know programatically 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天全站免登陆