binding - OutOfMemoryException with very simple WPF application with Entity Framework -
i have searched question, have found questions people loading tables millions of entries. not case in situation.
i new wpf , new entity framework. used visual studio 2010 data source wizard add connection database. used drag , drop drag view data source wpf window. view contains 32,000 records , takes 15 seconds select.
when built , ran application first time, worked fine , displayed data in window. feel difference, display same data in both listview , datagrid, no different when use 1 of controls:
when run application second time, never finishes starting up. displays 'busy' cursor , throws outofmemoryexception after while. if watch performance in task manager, memory keeps rising , rising until hits exception.
i have debugged this: not happen when executing ef query. have made save query results list , assign datasource of window. can see in debugger query terminates , list generated fine, can inspect in debugger.
it's data binding mechanism after query run seems leak memory nothing , throw. way, there no call stack post.
has else had problem, , how did solve it?
here more information: it's windows 7.
mainwindow.xaml looks this:
<window x:class="wpfapplication2.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525" loaded="window_loaded" mc:ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:wpfapplication2"> <window.resources> <collectionviewsource x:key="vmyviewsource" d:designsource="{d:designinstance my:vmyview, createlist=true}" /> </window.resources> <grid datacontext="{staticresource vmyviewsource}"> <grid.rowdefinitions> <rowdefinition height="20"/> <rowdefinition height="auto"/> <rowdefinition height="20"/> <rowdefinition height="*"/> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="*"/> </grid.columndefinitions> <textblock grid.row="0" text="my view in listview:"/> <listview grid.row="1" itemssource="{binding}" margin="0" name="vmylistview" selectionmode="single"> <listview.itemcontainerstyle> <style> <setter property="control.horizontalcontentalignment" value="stretch" /> <setter property="control.verticalcontentalignment" value="stretch" /> </style> </listview.itemcontainerstyle> <listview.view> <gridview> <gridviewcolumn x:name="idcolumn1" header="id" width="80"> <gridviewcolumn.celltemplate> <datatemplate> <textbox margin="6,-1,-6,-1" text="{binding path=id,mode=oneway, validatesonexceptions=true, notifyonvalidationerror=true}" /> </datatemplate> </gridviewcolumn.celltemplate> </gridviewcolumn> <gridviewcolumn x:name="name" header="name" width="80"> <gridviewcolumn.celltemplate> <datatemplate> <textbox margin="-6,-1" text="{binding path=name, mode=oneway, validatesonexceptions=true, notifyonvalidationerror=true}" /> </datatemplate> </gridviewcolumn.celltemplate> </gridviewcolumn> ... (more gridviewcolumns) </gridview> </listview.view> </listview> <textblock grid.row="2" text="my view in datagrid:"/> <datagrid grid.row="3" autogeneratecolumns="false" enablerowvirtualization="true" horizontalalignment="left" itemssource="{binding}" margin="0" name="vmyviewdatagrid" rowdetailsvisibilitymode="visiblewhenselected" verticalalignment="top" > <datagrid.columns> <datagridtextcolumn x:name="idcolumn" binding="{binding path=id}" header="id" width="sizetoheader" /> <datagridtextcolumn x:name="namecolumn" binding="{binding path=name}" header="name" width="sizetoheader" /> ... (more datagridtextcolumns, celltemplate textbox inside) </datagrid.columns> </datagrid> </grid> </window> and window_loaded method of mainwindow (most of code autogenerated data source wizard):
private void window_loaded(object sender, routedeventargs e) { wpfapplication2.myentities myentities = new wpfapplication2.myentities(); // load data vmyview. can modify code needed. system.windows.data.collectionviewsource vmyviewviewsource = ((system.windows.data.collectionviewsource)(this.findresource("vmyviewviewsource"))); system.data.objects.objectquery<wpfapplication2.vmyview> vmyviewquery = this.getvmyviewquery(myentities); var data = vmyviewquery.execute(system.data.objects.mergeoption.appendonly).tolist(); // added tolist() make query execute here vmyviewviewsource.source = data; } // gets here fine , loads data i can't believe there out of ordinary here, going on , how can rid of problem?
Comments
Post a Comment