.NET CF - MSMQ ActivateDevice() 崩溃

发布于 2024-09-28 19:59:25 字数 2584 浏览 0 评论 0原文

我有一个使用 MSMQ 的 .NET 3.5 Compact Framework 应用程序。 我们在 Intermec CN3、Windows Mobile 5.0 设备上运行此应用程序。

但是,当我们的应用程序首次尝试使用 ActivateDevice (pinvoke) 激活 MSMQ 服务时,应用程序崩溃,并且我们收到错误报告消息:

myApp.exe 出现问题

请将此问题告知 Microsoft,您无需支付任何费用。等等..

我们所做的是这样的:

  1. 硬重置设备
  2. 安装 NETCFv35.wm.armv4i.cab
  3. 安装 msmq.arm.CAB
  4. *运行设置 MSMQ 和注册表的 CF 控制台应用程序
  5. 软重置 PDA
  6. *运行我们的应用程序启动时调用ActivateDevice()

进行软重置后,第一次调用ActivateDevice() 时,应用程序会崩溃。

然而,现在我们已经调用了ActivateDevice(),MSMQ 服务至少在设备上工作,直到再次软重置为止。

此外,任何对 ActivateDevice() 的调用都不会导致应用程序崩溃。

我们在硬重置后运行的控制台应用程序基本上是这样的:

class InstallRegister
{
    public void Main()
    {
        RunMsmqAdmin("install");
        RunMsmqAdmin("register install");
        RunMsmqAdmin("register");

        SetQuotaValueRegistry("MachineQuota");
        SetQuotaValueRegistry("DefaultLocalQuota");
        SetQuotaValueRegistry("DefaultQuota");

        RunMsmqAdmin("enable binary");
        RunMsmqAdmin("enable srmp");
        RunMsmqAdmin("start");

        RegFlushKey(0x80000002);
    }

    private void SetQuotaValueRegistry(string quotaValueName)
    {
        Microsoft.Win32.Registry.SetValue(
                "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\"
                , quotaValueName
                , 100000);
    }

    private void RunMsmqAdmin(string command)
    {
        using (Process _process = new Process())
        {
            _process.StartInfo.FileName = @"\windows\msmqadm.exe";
            _process.StartInfo.Arguments = command;
            _process.StartInfo.UseShellExecute = true;
            _process.Start();
            _process.WaitForExit();
        }
    }
    [System.Runtime.InteropServices.DllImport("CoreDll.dll", EntryPoint = "RegFlushKey", SetLastError = true)]
    private static extern uint RegFlushKey(uint hKey);
}

我们的应用程序对ActivateDevice()的调用基本上是这样的:

class ActivateMSMQ
{
    public void Active()
    {
        var handle = ActivateDevice("Drivers\\BuiltIn\\MSMQD", 0);
        CloseHandle(handle);
    }
    [System.Runtime.InteropServices.DllImport("CoreDll.dll", SetLastError = true)]
    private static extern IntPtr ActivateDevice(string lpszDevKey, Int32 dwClientInfo);

    [System.Runtime.InteropServices.DllImport("CoreDll.dll", SetLastError = true)]
    private extern static Int32 CloseHandle(IntPtr hProcess);
}

每当设备软重置时,ActivateDevice()仍然会导致我们的应用程序崩溃。

有其他人在紧凑框架上使用 MSMQ 经历过这种情况吗?

I have a .NET 3.5 Compact Framework application that uses MSMQ.
We are running this application on an Intermec CN3, Windows Mobile 5.0 device.

However, when our application first tries to active the MSMQ service with ActivateDevice (pinvoke), the application crashes and we get the error report message:

A problem has occuurred with myApp.exe

Please tell Microsoft about this problem, at not cost to you. ect..

What we have done is this:

  1. Hard Reset the Device
  2. Install NETCFv35.wm.armv4i.cab
  3. Install msmq.arm.CAB
  4. *Run a CF console app that sets up MSMQ and the registry
  5. Soft reset the PDA
  6. *Run our application which calls ActivateDevice() on startup

After doing a soft reset, the first time that ActivateDevice() is called, the application crashes.

However, now that we have called ActivateDevice(), MSMQ services are working on the device atleast until it is soft reset again.

Also, any calls to ActivateDevice() will not crash the application.

The console app that we run after a hard reset is basically this:

class InstallRegister
{
    public void Main()
    {
        RunMsmqAdmin("install");
        RunMsmqAdmin("register install");
        RunMsmqAdmin("register");

        SetQuotaValueRegistry("MachineQuota");
        SetQuotaValueRegistry("DefaultLocalQuota");
        SetQuotaValueRegistry("DefaultQuota");

        RunMsmqAdmin("enable binary");
        RunMsmqAdmin("enable srmp");
        RunMsmqAdmin("start");

        RegFlushKey(0x80000002);
    }

    private void SetQuotaValueRegistry(string quotaValueName)
    {
        Microsoft.Win32.Registry.SetValue(
                "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\"
                , quotaValueName
                , 100000);
    }

    private void RunMsmqAdmin(string command)
    {
        using (Process _process = new Process())
        {
            _process.StartInfo.FileName = @"\windows\msmqadm.exe";
            _process.StartInfo.Arguments = command;
            _process.StartInfo.UseShellExecute = true;
            _process.Start();
            _process.WaitForExit();
        }
    }
    [System.Runtime.InteropServices.DllImport("CoreDll.dll", EntryPoint = "RegFlushKey", SetLastError = true)]
    private static extern uint RegFlushKey(uint hKey);
}

Our applications call to ActivateDevice() is basically this:

class ActivateMSMQ
{
    public void Active()
    {
        var handle = ActivateDevice("Drivers\\BuiltIn\\MSMQD", 0);
        CloseHandle(handle);
    }
    [System.Runtime.InteropServices.DllImport("CoreDll.dll", SetLastError = true)]
    private static extern IntPtr ActivateDevice(string lpszDevKey, Int32 dwClientInfo);

    [System.Runtime.InteropServices.DllImport("CoreDll.dll", SetLastError = true)]
    private extern static Int32 CloseHandle(IntPtr hProcess);
}

ActivateDevice() still causes our app the crash whenever the device is soft reset.

Has anyone else experienced this with MSMQ on the compact framework?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

GRAY°灰色天空 2024-10-05 19:59:26

是的,会出现这个问题。快速而简单的解决方法是将代码放入单独的可执行文件中,然后在应用程序启动时启动此进程并等待完成。该进程将因崩溃而终止,但将返回,并且您的调用应用程序仍然完好无损。然后只需确保可执行文件部署在您的驾驶室中,以便您的应用程序可以调用它。

Yes this problem occurs. the quick and easy fix for this is to put the code into a separate executable, then on the start of you app launch this process and wait for completion. The process will terminate due to the crash but will return with your calling app still intact. Then just make sure the executable is deployed in your cab so you app can call it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文