Socket.Disconnect(bool reuse)根据MSDN,程序可以重用套接字.我的问题是:
如果我们决定重用套接字,那意味着它会重用相同的本地端点吗?它会保留该套接字的端口还是仅仅(我不相信它)保存所有对象资源?
如果它实际上只保存资源,它们会被分配给下一个连接吗?如果是这样,发送/接收缓冲区会自动刷新还是有某种方式刷新它们?断断续续地Socket.ShutDown(ShutDown.Both)为我做这件事吗?
我会在什么情况下使用Socket.Disconnect(false)?如果所有目的都是为了重用套接字,这会给予我什么?
iv's遇到了XAML问题,在一个与vs2010一起工作的项目中,当我在XAML中使用DynamicResource时,我们使用了自己的CustomBinding,设计器通过以下理解得出了这一结论:
CustomBinding is not valid for Setter.Value.
The only supported MarkupExtension types are
DynamicResourceExtension and BindingBase or derived types.
Run Code Online (Sandbox Code Playgroud)
即使在该扩展中未使用它。
<SomeControl Value="{CustomBinding SomeValue}
Style="{DynamicResource SomeStyle}" />
Run Code Online (Sandbox Code Playgroud)
Style =“ {DynamicResource SomeStyle}”是引发设计时异常的部分,因此永远不会设置样式。
如果有人遇到类似问题,请告知。谢谢。
取自本书:"Julia Lerman - 编程实体框架"
在EF中创建新实体时:
var contact = Contact.CreateContact(0, "Camey", "Combs", DateTime.Now, DateTime.Now);
context.Contacts.AddObject(contact);
context.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
生成的sql:
exec sp_executesql N'insert [dbo].[Contact]([FirstName], [LastName], [Title],
[AddDate], [ModifiedDate])
values (@0, @1, null, @2, @3)
select [ContactID]
from [dbo].[Contact]
where @@ROWCOUNT > 0 and [ContactID] = scope_identity()',
N'@0 nvarchar(50),@1 nvarchar(50),@2 datetime2(7),@3 datetime2(7)',
@0=N'Camey',@1=N'Combs',@2='2009-08-30 09:27:31.7449098',
@3='2009-11-30 09:27:31.7449098'
Run Code Online (Sandbox Code Playgroud)
什么是@@ RowCount> 0用于where子句?
我不确定它根据msdn做了什么它会返回受影响的行数,所以据我所知,这只是验证添加了联系人记录的一种方式,他们也可以编写@@ ROWCOUNT = 1
它是否正确 ?
实施说明:
在每个CompositionTarget.Rendering事件中,我使用Writablebitmap绘制4条相邻的线条(这是"实时"线图的绘图仪).
问题:
这很有用,直到UI-Thread看起来很忙,然后下一个CompositionTarget.Rendering 事件需要更长时间才能触发.
题 :
是否有一些机制来保持一个恒定的渲染间隔,优先于任何其他UI操作?
可能的灵魂:
我正在考虑创建一个HostVisual以及如何为它分配一个DispatcherTimer,
这种方法会起作用吗?
想到的任何其他方法?
提前致谢 .
我有一个ItemsControl可以显示同一模板的多个实例。我需要能够在事件处理程序上执行代码,以便可以区分控件。
例如:我有一个杂货清单,因此我为每种食物都DataTemplate包含一个“购买” Button。我想将所述按钮绑定到代码,并告诉按下了哪个按钮。
考虑到我正在使用MVVM设计模式,我该如何做到这一点
** XAML:**
<ItemsControl ItemsSource="{Binding MyItemList}">
<ItemsControl.ItemsTemplate>
<DataTemplate>
<Button Content="Buy" />
</DataTemplate>
</ItemsControl.ItemsTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
所以,MyItemList是一个List<MyItem>实例。所述DataTemplate包含修改值或在执行代码中不存在控制MyItem:
我已经阅读了很多关于将模板出价到命令的文章,但是找不到使用项目列表的文章。
在我的应用程序中 有一个登录机制,用于保存一个cookie,其中包含刚刚登录的用户的信息
private void CreateCookie(LoginEventArgs args)
{
HttpCookie cookie = new HttpCookie("user");
cookie.Values["name"] = args.User_Name;
cookie.Values["id"] = args.ID;
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
}
Run Code Online (Sandbox Code Playgroud)
在我的母版页面加载我执行检查以查看此cookie是否存在:
HttpCookie cookie = Request.Cookies["user"] ;
if( (cookie != null) && (cookie.Value != ""))
{
if (Session["user"] == null)
Login_Passed(this, new LoginEventArgs(cookie.Values["name"].ToString(), int.Parse(cookie.Values["id"])));
}
Run Code Online (Sandbox Code Playgroud)
现在如果我登录(创建一个cookie),关闭浏览器,然后运行我的应用程序.再次,cookie存在,它的值是正确的,用户"自动"登录.
如果我首先从启动内容页面重定向到不同的内容页面,则cookie值也完好无损,
问题是当我第二次重定向回另一个内容页面时,主页面加载,检查cookie是否存在但是值被删除...
关于为什么会这样的想法?
也许我退出的方式可能是这个问题的原因:
当我注销时,我创建一个与1天前相同名称的cookie.
private void Remove_Cookie()
{
HttpCookie cookie = new HttpCookie("user");
cookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookie);
}
Run Code Online (Sandbox Code Playgroud)
在iv'e描述我没有正式退出的情况下,我只是结束我的应用程序,所以这不应该有任何影响.
我是regex的新手,我试图匹配一个有2位数字的情况都可以从0到9
一些东西
[0-9][0-9]
Run Code Online (Sandbox Code Playgroud)
例如 :
11 10 01
在我的WPF项目中,我使用复选框列构建了以下数据网格:
XAML
<DataGrid AutoGenerateColumns="False" TargetUpdated="IsIntermediatePointFixedByBracketDataGrid_TargetUpdated">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding="{Binding isFixedByBracket, NotifyOnTargetUpdated=True }" />
</DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
C#
private void IsIntermediatePointFixedByBracketDataGrid_TargetUpdated(object sender, DataTransferEventArgs e)
{
DataGrid dg = (DataGrid)sender;
if (dg.SelectedIndex != -1
&& ((IsFixedByBracketElement)dg.SelectedItem).isFixedByBracket != this.currentIntermediatePosition.isFixedByBracket[dg.SelectedIndex])
{
this.currentIntermediatePosition.isFixedByBracket[dg.SelectedIndex] =
((IsFixedByBracketElement)dg.SelectedItem).isFixedByBracket;
}
}
Run Code Online (Sandbox Code Playgroud)
当我选中/取消选中一个复选框时,会抛出TargetUpdated事件,但只有在我选择并取消选中包含该复选框的单元格时,该值才会更改.为什么会发生这种情况?我该如何改变这种行为?
本质上,我有一个主窗口,其上有一个用户控件,包含一个绑定到主窗口视图模型的属性.这个想法是当属性在用户表单中发生变化时,通过绑定主窗口视图模型中的属性也会发生变化.问题是,当用户控件没有ViewModel时,这是有效的,当我向用户控件添加一个简单的ViewModel时,绑定不再起作用.因为我需要为我的控件设置ViewModel,所以我需要弄清楚为什么添加ViewModel会破坏绑定以及如何修复它.欢迎任何建议.
public partial class Control1 : UserControl, INotifyPropertyChanged
{
public Control1()
{
InitializeComponent();
Loaded += Control1_Loaded;
}
void Control1_Loaded(object sender, RoutedEventArgs e)
{
DataContext = new Control1ViewModel();
}
public static DependencyProperty SavedStringProperty = DependencyProperty.Register(
"SavedString", typeof(string), typeof(Control1));
public string SavedString
{
get
{
return (string)GetValue(SavedStringProperty);
}
set
{
SetValue(SavedStringProperty, value);
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void FirePropChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
SavedString = "Hi";
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个
IEnumrable<PropertyInfo>
Run Code Online (Sandbox Code Playgroud)
我有一个名为Disassemble的方法,它以递归方式迭代抛出一个给定的对象及其所有属性的子对象.
请不要关注INameValueWrapper类型的Inner包装器对象
下面的问题是当我遇到一个属性,它是一个类我不想在它上面调用Disassemble并将它添加到IEnumrable的同一个迭代中,当它被调用时,Dissasemble不再出现在我放置注释的地方: //问题出在这里.
public static IEnumerable<T> Dissasemble<T>(this object sourceObj) where T : INameValueWrapper
{
var properties = sourceObj.GetType().GetProperties();
foreach (var prop in properties)
{
var wrapper = (T)prop.WrapPropertyInfo(sourceObj);
yield return wrapper;
if (wrapper is CollectionPropertyInfoWrapper)
{
var colWrapper = wrapper as CollectionPropertyInfoWrapper;
var collection = (IList)colWrapper.Value;
int index = 0;
foreach (var item in collection)
{
yield return (T)item.WrapItem(collection, index + 1);
index++;
}
}
else
{
var propWrapper = wrapper as PropertyInfoWrapper;
if (!propWrapper.IsPrimitive)
{
var …Run Code Online (Sandbox Code Playgroud)