Getting Currency Manager takes a long time

J

Joe

Why does BindingContext[dataSource, dataMemeber] as CurrencyManager take 40
seconds to return?

The dataSource which is a DataTable has 500k rows.

I'm using .NET 2.0 and have 2gigs of ram and dual 3.GHz Xeons

Thanks for any help,
Joe
 
W

WenYuan Wang

Hi Joe
I have tried some test according to your scenario.
- I create a datatable and add 500000 rows in datatable.
As below
--------------------------------------------
DataSet ds = new DataSet();
DataTable dt = new DataTable("testTable");
DataColumn dc = new DataColumn("test");
dt.Columns.Add(dc);
for (int i = 0; i < 500000; i++)
{
DataRow dr = dt.NewRow();
dr["test"] = i;
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "testTable";
CurrencyManager cm = this.BindingContext[ds, "testTable"] as
CurrencyManager;
--------------------------------------------

But, unfortunately, I can't reproduce the problem.
The "this. CurrencyManager cm = this.BindingContext[ds, "testTable"] as
CurrencyManager;" just take 0.0001 second to return.
The real reason causes this issue maybe not the "BindingContext[dataSource,
dataMemeber] as CurrencyManager" statement.

Do you have done a step debug to check which statement takes so long time
to execute.
And would you please provide me some code snippet.

If you have any concern, please feel free to let me know.
Sincerely,
Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

Joe

Hi Wen,

I hit pause (or step through) and the delay is at this line:
CurrencyManager manager = context[dataSource, dataMember] as
CurrencyManager;

context = this.BindingContext

-Joe
 
W

William \(Bill\) Vaughn

I'm not even going to ask why you think storing 1/2 million rows in a
DataTable makes sense...
This is like having someone complain that they can't get their Toyota 1/4
ton pickup started when it's buried under 20 tons of rock.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
Between now and Nov. 6th 2006 you can sign up for a substantial discount.
Look for the "Early Bird" discount checkbox on the registration form...
 
W

WenYuan Wang

Hi Joe
According to your reply I tried to test again.
I posted the follow statements:
-------------
//this.dataGridView1.DataSource = ds;
//this.dataGridView1.DataMember = "testTable";
BindingContext context = this.BindingContext;
CurrencyManager cm = context[ds, "testTable"] as CurrencyManager;
-------------
The issue has been reproduced.
The statement
------------
CurrencyManager cm = this.BindingContext[ds, "testTable"] as
CurrencyManager;
------------
It will take a long time to return when ds["testTable"] has 50k rows.
According to my research, I found that the actual reason causing this issue
is not "as CurrencyManager;" statement, but rather the
"BindingContext[dataSource, dataMemeber]" statement. It will take a long
time to return when the application is running under .Net 2.0 (this problem
isn't occur for .Net 1.1)
I think it could be an expected behavior in .net 2.0 due to additional
protection and checking code.
"this.BindContext[]" will do some checks on all the rows of DataTable when
DataTable hasn't been previously binding to any WinForm Controller (such as
DataGridView,ListBox,Combobox,Textbox..etc.).

Normally if we want to show the datatable in DatatGridView or Combobox, we
will set the databinding to our DataGridView or Combobox before we get the
"BindingContext".
Such as add the statement
"this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "testTable";"
before statement
"CurrencyManager cm = this.BindingContext[ds, "testTable"] as
CurrencyManager;".
According to my test, it will not take a long tome to return.

If there is anything unclear or anything more that I can help you with,
please don't hesitate to post them in the community.
Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
W

WenYuan Wang

Hi Joe,

How is it going with the problem?

If the problem is not resolved or you have anything unclear,
please feel free to post in the newsgroup and we will follow up.

Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

Joe

Hi Wen,

So if I understand correctly, I should assign ds to a WinForms control
before calling this.BindingContext[ds, dataMember] ? If this is true, I'll
try assigning it to a TextBox before assigning it to the control which is
doing the casting to the CurrencyManager.

Thanks,
Joe
 
W

WenYuan Wang

Hi, Joe

Yes, the BindingContext enables you to retrieve any particular
CurrencyManager associated with a data source.
But if there is no CurrencyManager associated with a data source, it will
take a long time to return.
So you should have a CurrencyManger in Winfrom before you get it.

However this.BindingContext[] is not used very often.
If you have assigned a dataset to a control, we recommend you use
CurrencyManager manager = this.ControlName.BindingContext[this.
ControlName.DataSource,this. ControlName.DataMember] as CurrencyManager;
to get the CurrencyManager.
This way you can get more performance.

Please pay attention to Textbox.
Textbox has some differences from DataGrid and ListBox.
You should use the following code snippet to get a BindingManager from
testbox.
Binding binding = nameTextBox.DataBindings["Text"];
BindingManagerBase manager = binding.BindingManagerBase;
manager.Position = manager.Position + 1;

If anything is unclear, please don't hesitate to post in the newsgroup and
we will follow up.

Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
W

WenYuan Wang

Hi Joe,

Just want to check if the issue has been resolved?
If it still persists, please don't hesitate to update here.
We'll go on to assist you on it. Thanks.

Best Regards,
Wen Yuan
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top