环境:VS2005,C#.net CF 2,Windows CE 5。尝试使用timer自动关闭对话框时出现异常。运行时错误信息:
“无法显示错误消息,原因是无法找到包含此错误消息的可选资源程序集”VS2005“调试模式”下可以看到如下输出:
在 System.ArgumentException 中第一次偶然出现的“System.Drawing.dll”类型的异常
未处理的“System.ArgumentException”类型的异常出现在 System.Drawing.dll 中。其他信息: 值不在预期的范围内。完整栈信息:> System.Drawing.dll!Microsoft.AGL.Common.MISC.HandleAr(Microsoft.AGL.Common.PAL_ERROR ar = BadParam) + 0x4b 字节
  System.Windows.Forms.dll!System.Windows.Forms.Form._CloseModal() + 0x1a 字节
  System.Windows.Forms.dll!System.Windows.Forms.Form.Close() + 0x16 字节
  Q0508.exe!Q0508.FormDialoge.timer1_Tick(object sender = {Interval = 3000}, System.EventArgs e = {System.EventArgs}) 行26 + 0x6 字节 C#
  System.Windows.Forms.dll!System.Windows.Forms.Timer._WnProc(Microsoft.AGL.Forms.WM wm = WM_TIMER, int wParam = 0, int lParam = 0) + 0x19 字节
  System.Windows.Forms.dll!System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(Microsoft.AGL.Forms.WM wm = WM_TIMER, int wParam = 298328, int lParam = 0) + 0x50 字节
  System.Windows.Forms.dll!Microsoft.AGL.Forms.EVL.EnterModalDialog(System.IntPtr hwnModal = 1114129)
  System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() + 0x60 字节
  Q0508.exe!Q0508.Form1.showdialog() 行51 + 0xb 字节 C#
  Q0508.exe!Q0508.Form1.timer1_Tick(object sender = {Interval = 1000}, System.EventArgs e = {System.EventArgs}) 行40 + 0xb 字节 C#
  System.Windows.Forms.dll!System.Windows.Forms.Timer._WnProc(Microsoft.AGL.Forms.WM wm = WM_TIMER, int wParam = 0, int lParam = 0) + 0x19 字节
  System.Windows.Forms.dll!System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(Microsoft.AGL.Forms.WM wm = WM_TIMER, int wParam = 298316, int lParam = 0) + 0x50 字节
  System.Windows.Forms.dll!Microsoft.AGL.Forms.EVL.EnterModalDialog(System.IntPtr hwnModal = 1114113)
  System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() + 0x60 字节
  Q0508.exe!Q0508.Form1.button1_Click(object sender = {Text = "button1"}, System.EventArgs e = {System.EventArgs}) 行34 + 0xb 字节 C#
  System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e = {System.EventArgs}) + 0x15 字节
  System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e = {System.EventArgs}) + 0x32 字节
  System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WnProc(Microsoft.AGL.Forms.WM wm = WM_BUTTON_NOTIFYCLICKED, int wParam = 0, int lParam = 0) + 0x17 字节
  System.Windows.Forms.dll!System.Windows.Forms.Control._InternalWnProc(Microsoft.AGL.Forms.WM wm = WM_BUTTON_NOTIFYCLICKED, int wParam = 0, int lParam = 0) + 0x9 字节
  System.Windows.Forms.dll!Microsoft.AGL.Forms.EVL.EnterMainLoop(System.IntPtr hwnMain = 2097165)
  System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form fm = {Q0508.Form1}) + 0x1a 字节
  Q0508.exe!Q0508.Program.Main() 行15 + 0xa 字节 C#主窗口    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();            g_DisplayAllMessage = new DelDisplayAllMessage(showdialog);
        }        private delegate void DelDisplayAllMessage();
        DelDisplayAllMessage g_DisplayAllMessage;        FormDialoge d1;
        FormDialoge d2;        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true; // 1000ms
            if (null == d1)
            {
                d1 = new FormDialoge();
            }
            d1.ShowDialog();
        }        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            g_DisplayAllMessage();
        }        private void showdialog()
        {
            if (null == d2)
            {
                d2 = new FormDialoge();
            }
            d2.ShowDialog();
        }
    }对话框代码using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace Q0508
{
    public partial class FormDialoge : Form
    {
        public FormDialoge()
        {
            InitializeComponent();
        }        private void FormDialoge_Load(object sender, EventArgs e)
        {
            this.timer1.Enabled = true;
        }        private void timer1_Tick(object sender, EventArgs e)
        {
            this.timer1.Enabled = false;
            this.Close(); // 因需求限制,关闭时不允许使用委托等异步方式。
        }
    }
}

解决方案 »

  1.   

    上面的代码没发现问题,是否问题在在其他代码?值不在预期的范围内: 
    说得很清楚,比如参数不能为null,你给一个null. 
    再比如值最大为5,你给个6.
      

  2.   

    wince 程序吗?没有开发过
      

  3.   


    首先,感谢关注!
    1,没有其他代码。发现这个问题的程序很复杂,但是简化成帖子所示代码,出现的问题是相同的。
    2,Form.Close(),本就没有什么参数的。
    3,同样的程序(.net CF版本),直接在PC上运行OK,利用断点,打出来Stack信息几乎一致。
    4,同样的代码放到标准.net版本生成的项目,编译后直接在PC上运行OK,利用断点查看Stack信息,也几乎一致。
      

  4.   


    WinCE 5 + .net CF 2.0