How to know programmatically whether Message Queueing is enabled on the machine or not?

前端 未结 4 1396
情深已故
情深已故 2021-02-20 15:18

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

But how to k

4条回答
  •  不思量自难忘°
    2021-02-20 16:06

    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 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? }
    

提交回复
热议问题