好吧,这看起来像.NET中的一个主要基本错误:
考虑以下简单程序,它故意尝试连接到不存在的数据库:
class Program
{
static void Main(string[] args)
{
Thread threadOne = new Thread(GetConnectionOne);
Thread threadTwo = new Thread(GetConnectionTwo);
threadOne.Start();
threadTwo.Start();
}
static void GetConnectionOne()
{
try
{
using (SqlConnection conn = new SqlConnection("Data Source=.\\wfea;Initial Catalog=zc;Persist Security Info=True;Trusted_Connection=yes;"))
{
conn.Open();
}
} catch (Exception e)
{
File.AppendAllText("ConnectionOneError.txt", e.Message + "\n" + e.StackTrace + "\n");
}
}
static void GetConnectionTwo()
{
try
{
using (SqlConnection conn = new SqlConnection("Data Source=.\\wfea;Initial Catalog=zc;Persist Security Info=True;Trusted_Connection=yes;"))
{
conn.Open();
}
}
catch (Exception e) …
Run Code Online (Sandbox Code Playgroud) 我试图摆脱所有的DateTime.Now
方法调用,并用我自己的GetNow()
方法替换它们,有时可能返回固定的日期用于测试目的.
我如何强制执行以后没有人添加DateTime.Now
电话?我可以使用NDepend或StyleCop在我的持续集成服务器上进行检查吗?
我在ASP.Net IIS应用程序上有一些带有时间戳的跟踪语句,可以获得大量流量.我在我的Global.asax中的Application_BeginRequest末尾和Application_PreRequestHandlerExecute的开头有跟踪语句.偶尔在BeginRequest结束和PreRequestHandlerExecute开始之间有一个很大的延迟,即超过5秒.
在这两个方法调用之间的HttpRequest生命周期中可能会花费多长时间?这是Windows Server 2008上的IIS7.
谢谢.
在C#中,我们现在可以使用花括号构造函数构造新对象,即
class Person {
readonly string FirstName {get; set;}
readonly string LastName {get; set;}
}
new Person { FirstName = "Bob", LastName = "smith" }
Run Code Online (Sandbox Code Playgroud)
我需要使用反射构造这个对象,但如果这些成员变量被标记为只读,我只能在构造函数中设置它们,并且只有花括号构造函数可用.有什么方法可以使用反射访问花括号样式的构造函数?谢谢.