今天我遇到了一个非常奇怪的问题.
尝试执行此C#代码:
class Program
{
static void Main(string[] args)
{
string yesterdayString = (DateTime.Now - TimeSpan.FromDays(1)).ToString("R");
string nowString = DateTime.Now.ToString("R");
DateTime.Parse(yesterdayString);
DateTime.Parse(nowString);
DateTime.Parse("Wed, 29 Feb 2012 18:05:49 GMT"); // this is what i have in yesterdayString
DateTime.Parse("Thu, 01 Mar 2012 18:05:40 GMT"); // this is what i have in nowString
}
}
Run Code Online (Sandbox Code Playgroud)
当然,你今天就会遇到问题.我添加了最后两个命令,让您知道问题所在.明天和整个三月份,DateTime.Parse将抛出一个FormatException(String未被识别为有效的DateTime.)
为什么?
是否有任何理由更喜欢在Windows窗体应用程序中实现全局异常处理程序的这些方法之一?
第一种方法
static void Main(string[] args)
{
try
{
System.Windows.Forms.Application.Run(mainform);
}
catch (Exception ex)
{
// Log error and display error message
}
}
Run Code Online (Sandbox Code Playgroud)
第二种方法
static void Main(string[] args)
{
System.Windows.Forms.Application.ThreadException +=
new ThreadExceptionEventHandler(Application_ThreadException);
System.Windows.Forms.Application.Run(mainform);
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
// Log error and display error message
}
Run Code Online (Sandbox Code Playgroud)
处理ThreadException事件会给你一些try/catch没有的东西吗?
我正在使用Janus GridEx控件.我正在使用计时器每分钟用数据库中的数据更新网格.如果用户在从数据库更新数据时选择了行,那么在更新完成后如何重新选择行?