就像在主题中一样:我想从文件(从流)读取数据到内存(memorystream)以提高我的应用程序速度.怎么做?
LazyThreadSafetyMode的文档指出,如果初始化方法(或默认构造函数,如果没有初始化方法)在内部使用锁,则使用值ExecutionAndPublication可能会导致死锁.我试图更好地理解使用此值时可能导致死锁的示例.在我使用这个值时,我正在初始化一个ChannelFactory.我看不到ChannelFactory的构造函数使用任何内部锁(使用Reflector查看类),所以我认为这种情况不适合可能的死锁情况,但我很好奇什么情况可能导致死锁以及是否有可能死锁初始化ChannelFactory.
总而言之,我的问题是:
是否可能导致使用ExecutionAndPublication初始化ChannelFactory的死锁?
使用ExecutionAndPublication导致死锁初始化其他对象有哪些可能的方法?
假设您有以下代码:
class x
{
static Lazy<ChannelFactory<ISomeChannel>> lcf =
new Lazy<ChannelFactory<ISomeChannel>>(
() => new ChannelFactory<ISomeChannel>("someEndPointConfig"),
LazyThreadSafetyMode.ExecutionAndPublication
);
public static ISomeChannel Create()
{
return lcf.Value.CreateChannel();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用此方法在表中插入一行:
MySqlConnection connect = new MySqlConnection(connectionStringMySql);
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = connect;
cmd.Connection.Open();
string commandLine = @"INSERT INTO Wanted (clientid,userid,startdate,enddate) VALUES" +
"(@clientid, @userid, @startdate, @enddate);";
cmd.CommandText = commandLine;
cmd.Parameters.AddWithValue("@clientid", userId);
cmd.Parameters.AddWithValue("@userid", "");
cmd.Parameters.AddWithValue("@startdate", start);
cmd.Parameters.AddWithValue("@enddate", end);
cmd.ExecuteNonQuery();
cmd.Connection.Close();
Run Code Online (Sandbox Code Playgroud)
我也有id列Auto Increment.我想知道是否有可能获得插入新行时创建的ID.
在公司我为我们计划的是预定要在2010年底我们目前有净的所有以前的版本上运行的生产应用发布多个项目.当项目开发开始时,我想考虑使用.Net 4.0.在此之前,我必须对提出这个想法感到很自在,并且还必须说服管理层.我正在寻找使用.Net 4.0框架开始一个新项目的意见,以及如果意见是应该使用最新的.Net框架的指导管理.需要考虑的一件事是我们目前使用的工具(Telerik和EntitySpaces)以及使用这些工具与.Net 4.0框架是否存在任何问题.上述两家供应商都声称产品在发布时可以随时使用.Net 4,但我知道无法保证.我期待着大家的反馈.我知道如果不在SO上发布情况,对这个主题的研究就不会完整:)
我有一个继承TextBoxClass的类,调用它MyTextBox
我想重新定义Background这个类的默认值.
所以我找了一种方法,找到了一个很好的选择:打电话 BackgroundProperty.OverrideMetadata()
麻烦的是:我可以把它放在哪里?
在App.OnStartup()?丑陋而不实用,我希望它在我的Class的代码文件中.
在班级的构造者?我得到一个例外:
PropertyMetadata已经为"MyTextBox"类型注册.
(对我来说似乎很好,我理解为什么我完美地得到这个)
所以我再次看了一下C#中的静态构造函数(之前没有关于那个,遗憾的是)
所以这是我的代码:
public class MyTextBox : TextBox
{
static MyTextBox()
{
MyTextBox.BackgroundProperty.OverrideMetadata(typeof(MyTextBox), new FrameworkPropertyMetadata(App.Current.Resources["CustomBackgroundBrush"]));
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我很高兴这一点,但微软不是.也就是说,当我使用代码分析功能时,我得到这个:
因此我的问题是:我能做些什么呢?
任何提示欢迎,谢谢
编辑:我要补充一点,我不完全理解为什么我会收到此警告,因为我没有在静态构造函数中初始化任何说法,或者是我?
我想在IIS 8应用程序池中为power shell脚本中的多个服务器启用自动启动和启动模式属性.我创建了一个适用于单个服务器的脚本.见下文:-
Import-Module WebAdministration
cd IIS:/AppPools
$ApplicationPools = dir
foreach ($item in $ApplicationPools)
{
$ApplicationPoolName = $item.Name
$pool = Get-Item $ApplicationPoolName
$pool.autoStart = 'false'
$pool.startmode = 'ondemand'
$pool | Set-Item
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我编辑多个服务器.我所有的服务器都在域中.
我正在尝试通过参数传递的名称来引用哈希表.
防爆.
TestScript.Ps1 -specify TestDomain1,TestDomain2
Run Code Online (Sandbox Code Playgroud)
TestScript.ps1的内容:
param(
[string[]]$specify
)
$TestDomain1 = @{"Name" = "Test1", "Hour" = 1}
$TestDomain2 = @{"Name" = "Test2", "Hour" = 2}
foreach($a in $specify)
{
write-host $($a).Name
#This is where I would expect it to return the Name value contained in the respective
# hash table. However when I do this, nothing is being returned
}
Run Code Online (Sandbox Code Playgroud)
还有另一种方法可以做到这一点来获得这些价值吗?有没有更好的方法而不是使用哈希表?任何帮助,将不胜感激.
我得到以下命令:
Get-Mailbox | Get-MailboxPermission | Select-Object Identity,User,AccessRights | Format-Table -AutoSize. 我希望能够PrimarySMTPAddress从我获得Get-Mailbox. 在我添加属性的那一刻,我PrimarySMTPAddress在列中什么也没有收到。
最终结果应该是这样的:
Identity User AccessRights PrimarySMTPAddress
-------- ------ ------------ ------------------
Domain.local/Users/Mailbox1 User1 {FullAccess} Mailbox1@Domain.local
Domain.local/Users/Mailbox2 User2 {FullAccess} Mailbox2@Domain.local
Domain.local/Users/Mailbox3 User3 {FullAccess} Mailbox3@Domain.local
Run Code Online (Sandbox Code Playgroud) 我有一个具有一个类型参数(T)的泛型类.我需要存储这些不同类型的通用对象的集合,因此我创建了一个通用类实现的接口,如此处所示.在迭代通过包含Interface对象集合的泛型列表时,我需要访问类型T的泛型类中的属性.到目前为止,我能够获得该值的唯一方法是使用反射调用方法.
interface ISomeClass {
//?
}
class SomeClass<T> : ISomeClass {
T ValueINeed { get; set;}
}
class ClassThatHasListOfGenericObjects{
List<ISomeClass> _l = new List<ISomeClass>();
public AddToList<T>(T someClass) : where T : ISomeClass {
_l.Add(someClass);
}
public SomeMethod(){
foreach(ISomeClass i in _l){
i.ValueINeed; //I don't know how to access the property in the generic class
}
}
}
Run Code Online (Sandbox Code Playgroud) 我无法通过密钥找到字典条目.我有一个如下界面:
public interface IFieldLookup
{
string FileName { get; set; }
string FieldName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个这样的字典:
Dictionary<IFieldLookup, IField> fd
Run Code Online (Sandbox Code Playgroud)
当我尝试通过键从字典中检索元素时,我得到一个KeyNotFoundException.我假设我必须实现某种类型的比较 - 如果我的假设是正确的,那么在这种情况下实施比较的推荐方法是什么?