Author Topic: BackgroundWorker and PaletteSet  (Read 2903 times)

0 Members and 1 Guest are viewing this topic.

MaksimS

  • Guest
BackgroundWorker and PaletteSet
« on: September 04, 2007, 08:10:33 AM »
Dear all,

I have a PaletteSet with a TreeView getting populated from some RDBMs. I was wondering if BackgroundWorker can be used for such asynchronous task, while preserving UI functionality of underlying PalleteSet?

Regards,
Maksim Sestic

MaksimS

  • Guest
Re: BackgroundWorker and PaletteSet
« Reply #1 on: September 04, 2007, 08:44:39 AM »
...Not that I didn't try it  :-) but it's not working as expected.

BackgroundWorker object is instantiated within Component's constructor (hosted inside PalleteSet). It means it's sitting on a calling thread. To avoid possible inter-threading problems I'm creating a new TreeView instance within DoWork handler, filling it's nodes from a database, and returning result to handler's Result property. RunWorkerCompleted handler receives resulting (e.Result) in-memory TreeView and parses it's nodes back to original TreeView hosted by a Component.

As a final result - Component's TreeView contains parsed nodes, they're there in it, but they're not displayed - TreeView remains (visually) empty.

Regards,
Maksim Sestic

« Last Edit: September 04, 2007, 08:46:17 AM by MaksimS »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8729
  • AKA Daniel
Re: BackgroundWorker and PaletteSet
« Reply #2 on: September 04, 2007, 09:50:28 AM »
Instead of creating a new instance of the control, how about creating a thread-safe container (ie a locked list), have a worker thread fill the container, use the RunWorkerCompleted event to populate the control from the data in the container, then update or refresh the control. Of course by now, you may have already guessed that I have no idea what I am talking about  :-o

MaksimS

  • Guest
Re: BackgroundWorker and PaletteSet
« Reply #3 on: September 04, 2007, 11:03:06 AM »
The thing is - background task works fine, the result it returns is OK, but repainting PaletteSet-hosted controls (TreeView) out of RunWorkerCompleted handler dosn't work. I just wanted to spare users waiting for the connection to get established, parsing results, etc. That's the time they could spend working with drawing, rather than staring into opened PaletteSet fetching some data.

Does anybody know, is there a way to get access to my PaletteSet object via it's contained controls?

Instead of creating a new instance of the control, how about creating a thread-safe container (ie a locked list), have a worker thread fill the container, use the RunWorkerCompleted event to populate the control from the data in the container, then update or refresh the control. Of course by now, you may have already guessed that I have no idea what I am talking about  :-o
« Last Edit: September 04, 2007, 11:04:58 AM by MaksimS »