C# DateTime中出现异常。添加
使用C#,.NET 4.0更新4.0.3,Windows 7 64位: 出于超出我职责范围的原因,我不得不让GUI线程在后台处理消息时“休眠”。到目前为止,这一切都完美无缺:C# DateTime中出现异常。添加,c#,.net,exception,datetime,C#,.net,Exception,Datetime,使用C#,.NET 4.0更新4.0.3,Windows 7 64位: 出于超出我职责范围的原因,我不得不让GUI线程在后台处理消息时“休眠”。到目前为止,这一切都完美无缺: private void SleepWithEventLoop(int ms) { var timeout = DateTime.UtcNow.AddMilliseconds(ms); while (DateTime.UtcNow < timeout &&
private void SleepWithEventLoop(int ms)
{
var timeout = DateTime.UtcNow.AddMilliseconds(ms);
while (DateTime.UtcNow < timeout && !disposed)
{
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(1);
}
}
但它还是坠毁了。重新安装.NET也不起作用。有什么想法吗
编辑:在两个同事的PC上出现相同的问题,但在新安装的VmWare系统上没有。看起来我们公司的电脑配置有点滑稽。DateTime是否需要任何“特殊”配置
编辑2:所以我通过p调用一个小的C DLL来“修复”这个问题,该DLL公开了time.h函数,它封装在一个类似DateTime的类中。在所有项目中搜索/替换。我觉得这样做很肮脏,但它至少解决了症状。当日程安排变得不那么紧张时,我会再次研究这个问题(是的,没错)。当我的代码在一台计算机上正常工作,而在另一台计算机上不正确工作时,我希望问题是我的应用程序正在使用DLL。所以我的建议是:
- 在您的计算机和它工作的VM上运行应用程序
- 在两台计算机上运行ProcessExplorer
- 在ProcessExplorer的下部窗格中显示DLL
- 比较DLL版本以查看哪些版本(如果有)不同
2012-12-18 12:50:41.204 | - None - | Exception | Exception caught: Der hinzuzufügende Wert war außerhalb des Bereichs.
| | | Parametername: value
| | | Details:
| | | bei System.DateTime.Add(Double value, Int32 scale)
| | | bei System.DateTime.AddMilliseconds(Double value)
| | | bei com.<...>.CanOpenProxyServer.SleepWithEventLoop(Int32 ms) in C:\Users\<...>\CanOpenProxy.cs:Zeile 78.
| | | bei com.<...>.CanOpenProxyServer.HandleConnection(MessageChannel channel) in C:\Users\<...>\CanOpenProxy.cs:Zeile 55.
while (true) SleepWithEventLoop(5);