GridView and Background Worker


Raoul Minder

Hi there

I have a simple Application with galleries on the left GridView and pictures
with some other data on the right GridView. I allow drag and drop to add new
pictures from the file system. Both GridViews are bound to my dataset,
handled by a simple page controller (not a real mvc implementation).

After dragging files onto the itemGrid, a worker ist started:

AddItemsWorker addItemsWorker;
addItemsWorker = new AddItemsWorker(_EventStopThread,
_EventThreadStopped, this, droppedFiles);

Using a foreach loop, the worker asks the form controller to add every
single image into the dataset and informs the GUI

file, false);
_form.Invoke(_form._DelegateThreadAddItemsUpdated, new Object[] {
status });

The controller applies an AcceptChanges on the row. The form binds data
again for both gridviews, otherwise the grid has no information about the
new row:

itemBindingSource.DataSource = null;
galleryBindingSource.DataSource = null;

galleryBindingSource.DataSource = GalleryController.GalleryDataSet;
galleryBindingSource.DataMember = "Gallery";

itemBindingSource.DataSource = galleryBindingSource;
itemBindingSource.DataMember = "FK_Gallery_Item";

That works always fine while starting from Visual Studio but when I start
the release exe, the application stopps responding that moment, the next
picture that overflows the window border should be showed (and a scrollbar
should be displayed).

First: I think it's a bad implementation from my side, because I am not
thread safe with my dataset.
Second: It is strange, because it only happens when I start the exe but
never with visual studio (why?)

- I could disable binding until finished but I like the effect to see every
new picture 'sliding' into the gridvew. Each image takes about a second to
display because the controller takes some resizing and other manipulation on
the picture. It would be annoying to wait 20 seconds in front of an empty

- I could lock the dataset while adding but I don't know the side effects
for the binding

- I could send the picture within the update delegate object (at the moment
only status information for the process bar), probably the only correct way.

What do you think about this?

Cheers, Raoul

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