【问题标题】:Prevent application start fail if MSMQ not installed如果未安装 MSMQ,防止应用程序启动失败
【发布时间】:2013-04-08 17:23:26
【问题描述】:

我在我的 .NET 应用程序中使用 MSMQ。 如果 MSMQ 已安装但未运行 - 可以处理。

但是如果本地计算机上没有安装 MSMQ 功能,如何防止启动时崩溃?

【问题讨论】:

    标签: .net windows msmq messages


    【解决方案1】:

    它并不漂亮,但我以前使用过它并取得了一些成功:

    public static bool IsMsmqInstalled
    {
        get
        {
            try
            {
                IntPtr result = NativeMethods.LoadLibrary("Mqrt.dll");
                return (result != IntPtr.Zero);
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
    
    public sealed class NativeMethods
    {
        [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
        internal static extern IntPtr LoadLibrary(string lpFileName);
    }
    

    【讨论】:

      【解决方案2】:

      这是我的博客:

      How to tell if MSMQ is installed

      【讨论】:

      • 是的,但是应用程序在启动之前就崩溃了,然后 CLR 尝试加载它(
      猜你喜欢
      • 2011-06-17
      • 2011-06-27
      • 2021-03-01
      • 2017-10-22
      • 1970-01-01
      • 2021-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多