c# - 跟踪 Application_ThreadException 的原因/位置
问题描述
我有一个随机抛出异常的应用程序。这是一个并发问题,但我不太清楚从哪里开始。
我无法在测试环境中实现它,我需要一些帮助来扩展我的异常日志记录,以便我可以找到导致问题的确切行并开始查找原因。
我喜欢任何和所有的建议
我得到了这个异常和堆栈跟踪
ex.message = Object is currently in use elsewhere.
Exception caught at: WndProcException() ==> OnThreadException() ==> Application_ThreadException(sender, ete)
ex. stackTrace: at System.Drawing.Graphics.GetHdc()
at System.Drawing.BufferedGraphics.RenderInternal(HandleRef refTargetDC, BufferedGraphics buffer)
at System.Drawing.BufferedGraphics.Render()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
它似乎是一个在访问时正在使用/删除的按钮控件,所以我一直在查看我所有的按钮用法
用于在按钮上绘制的绘制函数 readonly static Font LagerFont_B = new Font("Verdana", 8F, FontStyle.Bold);
public static void B_Paint(object sender, PaintEventArgs e)
{
try
{
Button b = sender as Button;
int p = (int)b.Tag;
Paint_Red_corner(e, p);
if (!DataStore.System.Lager_Status_Enable || b.Tag == null)
{
((Button)sender).Enabled = true;
return;
}
if (!DataStore.DATA__Produkter_dic.ContainsKey(p) || !DataStore.DATA__Produkter_dic[p].p.Lager.Lagerstyring_Aktiv)
{
((Button)sender).Enabled = true;
return;
}
decimal l = DataStore.DATA__Produkter_dic[p].p.Lager.Antal_på_Lager;
if (l == decimal.MinValue)
{
((Button)sender).Enabled = true;
return;
}
if (l < 1)
{
const int border = 20;
((Button)sender).Enabled = false;
e.Graphics.DrawLine(new Pen(Color.Black, 3), border, border, b.Width - border, b.Height - border);
e.Graphics.DrawLine(new Pen(Color.Black, 3), b.Width - border, border, border, b.Height - border);
}
else
{
((Button)sender).Enabled = true;
e.Graphics.DrawString(l.ToString("F0"), LagerFont_B, Brushes.Black, new PointF(5, 5));
}
}
catch (Exception)
{
}
}
public static void Paint_Red_corner(PaintEventArgs e, int p)
{
try
{
if (!DataStore.Is_Segment(segment.SUNSET) && DataStore.Kort.Kampagner.Kampagner_eksisterer)
{
if (DataStore.Kort.Kampagner.Findes_Produkt_til_Udlevering(p))
{
Point[] points0 = { new Point(0, 0), new Point(0, 25), new Point(25, 0) };
Point[] points1 = { new Point(2, 2), new Point(2, 20), new Point(20, 2) };
e.Graphics.FillPolygon(Brushes.Black, points0);
e.Graphics.FillPolygon(Brushes.Red, points1);
}
}
}
catch (Exception)
{
}
}
解决方案
推荐阅读
- php - 在 PHP 中使用字符串作为单元测试名称
- github - Git页面没有更新
- android - Dagger2 - 未生成应用程序组件
- python - 如何使用 Beautiful soup 从网页中抓取表格
- angular - ngModel 的角度选择默认值不在选择元素上工作,而是在另一个元素上工作
- node.js - 根据常见的 json 模式返回响应
- java - Spring data JPA - 从本机查询返回的映射对象到 POJO
- java - 按下警报对话框按钮总是返回 0 值
- spring-aop - 检查 Spring AOP 上的连接点是否为空
- python - 如何在浏览器关闭时使用 python-django 实现自动注销