gpt4 book ai didi

c# - 我该如何调试这个与线程相关的错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:17 26 4
gpt4 key购买 nike

我有一个大项目,当我按下一个按钮时,我开始了一个任务:

Task.Factory.StartNew(() =>
{
CreatePortfolio();
});

表单有一个 MSChart,我为每个访问图表的方法都有一个委托(delegate)。

当我单步执行代码时,不会抛出任何错误。但是当我运行它时,我得到了这个错误 - 但不知道它来自哪里,因为它显示在下面的 Application.Run 行上:

public static string[] MainArgs;
[STAThread]
static void Main(string[] args)
{
CheckForIllegalCrossThreadCalls = false;
MainArgs = args;

Application.Run( new MainForm( ) ); //ERROR shown here
}

异常(exception)情况:

System.ArgumentOutOfRangeException was unhandled
HResult=-2146233086
Message=Years value must be between +/-10000.
Parameter name: years
Source=mscorlib
ParamName=years
StackTrace:
at System.DateTime.AddYears(Int32 value)
at System.Windows.Forms.DataVisualization.Charting.ChartHelper.GetIntervalSize(Double current, Double interval, DateTimeIntervalType type, Series series, Double intervalOffset, DateTimeIntervalType intervalOffsetType, Boolean forceIntIndex, Boolean forceAbsInterval)
at System.Windows.Forms.DataVisualization.Charting.ChartHelper.GetIntervalSize(Double current, Double interval, DateTimeIntervalType type, Series series, Double intervalOffset, DateTimeIntervalType intervalOffsetType, Boolean forceIntIndex)
at System.Windows.Forms.DataVisualization.Charting.Axis.FillLabels(Boolean removeFirstRow)
at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetDefaultAxesValues()
at System.Windows.Forms.DataVisualization.Charting.ChartArea.SetData(Boolean initializeAxes, Boolean checkIndexedAligned)
at System.Windows.Forms.DataVisualization.Charting.ChartArea.ReCalcInternal()
at System.Windows.Forms.DataVisualization.Charting.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly)
at System.Windows.Forms.DataVisualization.Charting.Chart.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:

最佳答案

我认为您在某些时候正在使用 DateTime.AddYears 并且传递给 add years 的值无效。

请检查我认为您正在使用某个数组并从该数组的某个索引传递值,并且在某一时刻传递了数组中不可用的值。这是你的问题

关于c# - 我该如何调试这个与线程相关的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38484427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com