小编kev*_*v22的帖子

DateTime.Parse今天失败(2012年3月1日)!O_0

今天我遇到了一个非常奇怪的问题.

尝试执行此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.)

为什么?

c# datetime parsing

7
推荐指数
1
解决办法
3646
查看次数

处理Application.ThreadException和在Try/Catch中包装Application.Run之间的区别

是否有任何理由更喜欢在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没有的东西吗?

c# exception-handling winforms

3
推荐指数
1
解决办法
874
查看次数

在runTime中选择GridEx中的行

我正在使用Janus GridEx控件.我正在使用计时器每分钟用数据库中的数据更新网格.如果用户在从数据库更新数据时选择了行,那么在更新完成后如何重新选择行?

c# janus gridex

1
推荐指数
1
解决办法
4985
查看次数

标签 统计

c# ×3

datetime ×1

exception-handling ×1

gridex ×1

janus ×1

parsing ×1

winforms ×1