当我处理小文件(<= 32x32)时,我看到性能计数器"#Indinal GC"(在一个完美的应用程序中应保持为零)迅速增加WriteableBitmap
.
虽然这不是一个小应用程序内部的重大瓶颈,但是当内存中存在数千个对象时,它变成了一个非常大的问题(应用程序冻结在99.75%"GC中的时间",在每个步骤几秒钟)(例如:EntityFramework
上下文加载了许多实体和关系).
综合测试:
var objectCountPressure = (
from x in Enumerable.Range(65, 26)
let root = new DirectoryInfo((char)x + ":\\")
let subs =
from y in Enumerable.Range(0, 100 * IntPtr.Size)
let sub =new {DI = new DirectoryInfo(Path.Combine(root.FullName, "sub" + y)), Parent = root}
let files = from z in Enumerable.Range(0, 400) select new {FI = new FileInfo(Path.Combine(sub.DI.FullName, "file" + z)), Parent = sub}
select new {sub, files = files.ToList()}
select new {root, subs …
Run Code Online (Sandbox Code Playgroud) 我用这种方式使用CrmSvUtil:
crmsvcutil.exe /url:http://crm2011/MyTestOrg/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /namespace:Xrm /serviceContextName:XrmDataContext
Run Code Online (Sandbox Code Playgroud)
输出包含数千个业务对象和此上下文类:
[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "5.0.9688.1533")]
public partial class XrmDataContext : Microsoft.Xrm.Sdk.Client.OrganizationServiceContext
Run Code Online (Sandbox Code Playgroud)
但是看一下这些示例(即.\ sdk\walkthroughs\portal\consoleappwalkthrough),我清楚地看到上下文类应该从一个更强大的OrganizationServiceContext子类派生 - > CrmOrganizationServiceContext:
[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "5.0.9688.583")]
public partial class XrmServiceContext : Microsoft.Xrm.Client.CrmOrganizationServiceContext
Run Code Online (Sandbox Code Playgroud)
我绝对需要CrmOrganizationServiceContext,因为只有这时我才有我需要的构造函数.那么我做错了什么或我错过了哪种设置?
我在Model-First模式(= EDMX)中使用System.Data.SQLite 1.0.90与VS2013和EntityFramework 5.
我创建了一个包含表的新SQLite数据库:
CREATE TABLE [..]
[Test1integer] integer,
[Test2int] int,
[Test3smallint] smallint,
[Test4tinyint] tinyint,
[Test5bigint] bigint,
[Test6money] money,
[Test7float] float,
[Test8real] real,
[Test9decimal] decimal,
[Test10numeric18_5] numeric(18,5), [..]
Run Code Online (Sandbox Code Playgroud)
相关部分是Test7float
和Test8real
.
从数据库执行更新模型后... EDMX现在包含:
<Property Name="Test1integer" Type="integer" />
<Property Name="Test2int" Type="int" />
<Property Name="Test3smallint" Type="smallint" />
<Property Name="Test4tinyint" Type="tinyint" />
<Property Name="Test5bigint" Type="integer" />
<Property Name="Test6money" Type="decimal" Precision="53" Scale="0" />
<Property Name="Test7float" Type="real" />
<Property Name="Test8real" Type="real" />
<Property Name="Test9decimal" Type="decimal" Precision="53" Scale="0" />
<Property …
Run Code Online (Sandbox Code Playgroud) 我已经使用内存分析器检查了这个,并且没有真正的实体保留在内存中,但是散列集,字典和EntityKey对象 - 但我发现如何断开这些引用.
这么简单的问题:如何阻止上下文(或其ObjectStateManager)的大小无限增长?
[是的,我知道应该避免长时间的生活环境,但在这种情况下,这是一个复杂的分析运行,需要加载几个分层数据(下面的示例只是一个最小的问题演示)所以最后它是一个"短"生活的单一操作环境.]
重现的步骤:
代码[已更新,不再需要真正的数据库连接]:
class Program
{
static void Main()
{
const double MiB = 1024 * 1024;
using ( var context = new NorthwindEntities() )
{
var last = GC.GetTotalMemory(true) / MiB;
Console.WriteLine("before run: {0:n3} MiB", last);
var id = 0;
while ( true )
{
Run(context, ref id);
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var current = GC.GetTotalMemory(true) / MiB;
Console.WriteLine("after run: {0:n3} MiB (+{1:n3} MiB)", current, current - …
Run Code Online (Sandbox Code Playgroud) 如果您运行下面的示例窗口,则上面的ItemsControl将更新布局几秒钟,直到最后所有列都具有正确的宽度(正确=与较低ItemsControl中的列相同).
您可以更改窗口的宽度并水平和垂直滚动ScrollViewer周围的较低ItemsControls - 但只要更改窗口的高度,布局就会翻转几秒钟.
注意:没有像网格无限更新大小的其他问题那样的大小调整歧义.
是我做错了什么 - 如果是的话,我怎么能解决这个问题? - 或者我应该将此问题发布到Microsoft-Connect?
代码背后:
namespace DynamicGridColumnBinding
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
public partial class MainWindow
{
private static readonly CultureInfo[] cultureInfos =
CultureInfo.GetCultures(CultureTypes.NeutralCultures).Take(15).ToArray();
public MainWindow()
{
this.InitializeComponent();
}
public static IEnumerable<CultureInfo> AllCultures
{
get { return cultureInfos; }
}
private void GridInitialized(object sender, EventArgs e)
{
var grid = (Grid)sender;
for ( int i = 0; i < cultureInfos.Length; i++ )
grid.ColumnDefinitions.Add(new ColumnDefinition
{
Width …
Run Code Online (Sandbox Code Playgroud) 有没有窥探工具提示的技巧?因为一旦鼠标移到它上面它就会消失,所以没有机会按 ctrl+shift+click。
有没有人使用BitmapMetadata
内部使用WIC(Windows Imaging Component)的WPF类成功读取GPS数据?
我有一个图像,其中Windows(8.1)资源管理器和XnView等外部工具显示GPS坐标.
我尝试使用类BitmapMetadata
通过Metadata
类的属性提取这些数据BitmapFrame
:
var md = (BitmapMetdata)extractedFrame.Metadata;
var altitude = md.GetQuery("System.GPS.Altitude");
var altitudeProxy = md.GetQuery("System.GPS.Altitude.Proxy");
var altitudeRef = md.GetQuery("System.GPS.AltitudeRef");
var longitude = md.GetQuery("System.GPS.Longitude");
var longitudeProxy = md.GetQuery("System.GPS.Longitude.Proxy");
var longitudeRef = md.GetQuery("System.GPS.LongitudeRef");
var latitude = md.GetQuery("System.GPS.Latitude");
var latitudeProxy = md.GetQuery("System.GPS.Latitude.Proxy");
var latitudeRef = md.GetQuery("System.GPS.LatitudeRef");
Run Code Online (Sandbox Code Playgroud)
的结果altitude
(System.Double),altitudeRef
(System.Byte),longitudeRef
(System.String)和latitudeRef
(System.String)都确定和检索合理的数据( "510.70", "0", "N", "E").
longitude
并且latitude
应该是System.Double的数组,但它们始终为NULL.
使用".Proxy"后缀的结果返回奇怪的String数据,我不知道如何解析它们以及它们是否是文化不变的:MSDN文档告诉一些不同的东西,没有关于字符串的东西; 但至少那里有经度和纬度的"有效"数据.
错过了什么是错误或我的错?
拿这个小脚本(在 LINQPad 中设计,但应该在任何地方运行):
void Main()
{
Task.Run(() => Worker()).Wait();
}
async Task Worker()
{
if (SynchronizationContext.Current != null)
throw new InvalidOperationException("Don't want any synchronization!");
BaseClass provider = new Implementation();
Func<IObserver<TimeSpan>, CancellationToken, Task> subscribeAsync =
provider.CreateValues;
var observable = Observable.Create(subscribeAsync);
var cancellation = new CancellationTokenSource(5500).Token; // gets cancelled after 5.5s
cancellation.Register(() => Console.WriteLine("token is cancelled now"));
await observable
.Do(ts =>
{
Console.WriteLine("Elapsed: {0}; cancelled: {1}",
ts,
cancellation.IsCancellationRequested);
cancellation.ThrowIfCancellationRequested();
})
.ToTask(cancellation)
.ConfigureAwait(false);
}
abstract class BaseClass
{
// allow implementers to use …
Run Code Online (Sandbox Code Playgroud) 仅当实现实体DbEntityEntry.State与"Unchanged"不同时,才会调用IValidatableObject.Validate.只是更改导航属性不会改变状态,因此永远不会发生验证.
为什么微软总是发布半生不熟的测试版?
我甚至无法手动检测导航属性的变化:
var changes = context.ChangeTracker.Entries()
.Where(e => e.State != EntityState.Unchanged)
.ToArray();
Run Code Online (Sandbox Code Playgroud)
返回一个空数组.
.net ×8
c# ×5
wpf ×4
.net-4.0 ×1
memory-leaks ×1
performance ×1
snoop ×1
sqlite ×1
validation ×1
wic ×1
windows ×1
xaml ×1