我有一个随机抛出异常的应用程序。 这显然是一个并发问题,但我不知道从哪里开始。
我无法使其在测试环境中发生,并且我希望在扩展异常日志记录方面有所帮助,以便我找到导致问题的确切信息,并开始寻找原因。
我提出所有建议
我得到了这个异常和堆栈跟踪
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)
似乎是在访问时正在使用/删除的按钮控件,所以我一直在查看我所有的按钮用法
用于在按钮上绘画的绘画功能 只读静态字体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)
{
}
}