By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,975 Members | 1,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,975 IT Pros & Developers. It's quick & easy.

DataSet and thread

P: n/a
Hi.

I have DataGridView bound to my dataset through bindingsource component. My
dataset is filled on separate thread. While this thread is working I receive
"Cross-thread operation not valid" exception because bindingsource tries to
update grid cells from another thread (invoke is required).
How to handle such scenario ?

Thanks

SS

Dec 19 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Dec 19, 10:37 am, "shark" <m...@poczta.onet.plwrote:
I have DataGridView bound to my dataset through bindingsource component. My
dataset is filled on separate thread. While this thread is working I receive
"Cross-thread operation not valid" exception because bindingsource tries to
update grid cells from another thread (invoke is required).
How to handle such scenario ?
You either need to temporarily unbind the data source while it's being
filled, or fill to a "temporary" dataset that you then copy over on
the UI thread. (At least, that's my understanding of the situation. I
agree it's not terribly pleasant.)

Jon
Dec 19 '07 #2

P: n/a
Grid bindings are unfortunately very thread-sensitive. For simple
bindings (to individual properties) I have a workaround - but for this
scenario I'm afraid you're either going to have to do manual binding,
or suspend the binding while you populate the dataset on the worker
thread and reinstate once ready.

Marc
Dec 19 '07 #3

P: n/a
I'm calling bindingsource.SuspenBinding just before Thread is started. It
works fine, but my question is what will hapen to data is user change it
manually and then I call bindingsource.ResumeBinding ?
Data will be overriden ? or merged?

Thanks

SS

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:ae**********************************@e4g2000h sg.googlegroups.com...
On Dec 19, 10:37 am, "shark" <m...@poczta.onet.plwrote:
>I have DataGridView bound to my dataset through bindingsource component.
My
dataset is filled on separate thread. While this thread is working I
receive
"Cross-thread operation not valid" exception because bindingsource tries
to
update grid cells from another thread (invoke is required).
How to handle such scenario ?

You either need to temporarily unbind the data source while it's being
filled, or fill to a "temporary" dataset that you then copy over on
the UI thread. (At least, that's my understanding of the situation. I
agree it's not terribly pleasant.)

Jon
Dec 19 '07 #4

P: n/a
shark <ma**@poczta.onet.plwrote:
I'm calling bindingsource.SuspenBinding just before Thread is started. It
works fine, but my question is what will hapen to data is user change it
manually and then I call bindingsource.ResumeBinding ?
Data will be overriden ? or merged?
It's not quite clear what sequence of events you're worried about.
Could you spell it out in more detail?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 19 '07 #5

P: n/a
OK, so
1. bindingsource.SuspenBinding
2. Thread is started
3. Thread is pulling data to dataset
4. User is working with DataGridView (which is unbound from dataset) and is
changing data in it
5. Thread stops
6. bindingsource.ResumeBinding

What will happen to my dataset ?

Thx

SS

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
shark <ma**@poczta.onet.plwrote:
>I'm calling bindingsource.SuspenBinding just before Thread is started. It
works fine, but my question is what will hapen to data is user change it
manually and then I call bindingsource.ResumeBinding ?
Data will be overriden ? or merged?

It's not quite clear what sequence of events you're worried about.
Could you spell it out in more detail?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 19 '07 #6

P: n/a
SS,

This scenario shouldn't be allowed to happen. You should be disabling
access to the data grid view while the thread is updating the underlying
data that the user is seeing in the grid.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"shark" <ma**@poczta.onet.plwrote in message
news:fk**********@news.onet.pl...
OK, so
1. bindingsource.SuspenBinding
2. Thread is started
3. Thread is pulling data to dataset
4. User is working with DataGridView (which is unbound from dataset) and
is changing data in it
5. Thread stops
6. bindingsource.ResumeBinding

What will happen to my dataset ?

Thx

SS

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
>shark <ma**@poczta.onet.plwrote:
>>I'm calling bindingsource.SuspenBinding just before Thread is started.
It
works fine, but my question is what will hapen to data is user change it
manually and then I call bindingsource.ResumeBinding ?
Data will be overriden ? or merged?

It's not quite clear what sequence of events you're worried about.
Could you spell it out in more detail?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Dec 19 '07 #7

P: n/a
I'm going to do this (disable grid) but I just wonder what could happpen

Thx

SS

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:ON**************@TK2MSFTNGP03.phx.gbl...
SS,

This scenario shouldn't be allowed to happen. You should be disabling
access to the data grid view while the thread is updating the underlying
data that the user is seeing in the grid.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"shark" <ma**@poczta.onet.plwrote in message
news:fk**********@news.onet.pl...
>OK, so
1. bindingsource.SuspenBinding
2. Thread is started
3. Thread is pulling data to dataset
4. User is working with DataGridView (which is unbound from dataset) and
is changing data in it
5. Thread stops
6. bindingsource.ResumeBinding

What will happen to my dataset ?

Thx

SS

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com ...
>>shark <ma**@poczta.onet.plwrote:
I'm calling bindingsource.SuspenBinding just before Thread is started.
It
works fine, but my question is what will hapen to data is user change
it
manually and then I call bindingsource.ResumeBinding ?
Data will be overriden ? or merged?

It's not quite clear what sequence of events you're worried about.
Could you spell it out in more detail?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Dec 19 '07 #8

P: n/a
It really depends on what the other thread is doing, and what the user
is going to do. If what they are updating are separate, disparate parts of
the data, then nothing would happen. However, whether or not it is
disparate is something that is specific to your app and your data.

Regardless, it's not something I would consider allowing, unless you
have a severe need for it (in which case, you will have to find out how to
do it the right way, with proper synchronization).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"shark" <ma**@poczta.onet.plwrote in message
news:fk**********@news.onet.pl...
I'm going to do this (disable grid) but I just wonder what could happpen

Thx

SS

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:ON**************@TK2MSFTNGP03.phx.gbl...
>SS,

This scenario shouldn't be allowed to happen. You should be disabling
access to the data grid view while the thread is updating the underlying
data that the user is seeing in the grid.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"shark" <ma**@poczta.onet.plwrote in message
news:fk**********@news.onet.pl...
>>OK, so
1. bindingsource.SuspenBinding
2. Thread is started
3. Thread is pulling data to dataset
4. User is working with DataGridView (which is unbound from dataset) and
is changing data in it
5. Thread stops
6. bindingsource.ResumeBinding

What will happen to my dataset ?

Thx

SS

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.co m...
shark <ma**@poczta.onet.plwrote:
I'm calling bindingsource.SuspenBinding just before Thread is started.
It
works fine, but my question is what will hapen to data is user change
it
manually and then I call bindingsource.ResumeBinding ?
Data will be overriden ? or merged?

It's not quite clear what sequence of events you're worried about.
Could you spell it out in more detail?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Dec 19 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.