Omgili, forum search, forums search, search forums, discussion search,discussions search, search discussions, board search, boards search, search boards
  Advanced Search

Report progess during black box process

On Thu, 7 May 2009 20:25:30 -0700 (PDT), Bill <...@yahoo.com

I am using a dataview to sort a table that can have a million or so
rows. I am reporting to the user the progress while rows are added,
but when the code executes the Sort method there is no progress
reported until the sort finishes, which can take more than a minute
and the Task Manager indicates the application is not responding. I
dont want users to think it has hung. I was thinking about using a
timer to periodically display something, but the process is being
executed in a backgroundworker. Any suggestions?

Bill



On Thu, 07 May 2009 20:49:29 -0700, "Peter Duniho" <...@nnowslpianmk.com

On Thu, 07 May 2009 20:25:30 -0700, Bill <...@yahoo.com

Can you be more specific about what the problem is?

Since you're already running the sort with a BackgroundWorker, the UI
should be free to display whatever progress/activity you deem fit. A
timer would be fine, or I think there's a "marquee" mode for ProgressBar
where it just animates a visual across the bar rather than filling it.

Providing precise progress for the sort would be tricky, but you could
probably fake it a bit if you are willing to provide a custom comparison
function. The quicksort algorithm used is n log n, so you should be able
to make a good guess as to the number of times your comparison function
will get called with that calculation (there might be a non-"1" constant
in there somewhere, but even a simple empirical test should uncover that).

Of course, if you're willing to implement your own quicksort (not that
hard), you have complete access to the implementation and can track
progress precisely. :)

Pete

On Thu, 7 May 2009 21:13:29 -0700 (PDT), Pavel Minaev <...@gmail.com

On May 7, 8:25 pm, Bill <...@yahoo.com
If you read the documentation on BackgroundWorker (see ReportProgress
method and ProgressChanged event), you'll see that it specifically
includes means to marshal progress information from worker thread to
the UI thread, presumably so that the latter can display it in some
way.

Also, if you actually perform your sort entirely in BackgroundWorker,
then your application should not be reported as "not responding". If
it does that, then you aren't telling the whole story here. Or are you
doing the sort in BackgroundWorker, but block the UI thread waiting
for it to finish??

On Fri, 8 May 2009 00:12:27 -0400, "Mr. Arnold" <MR. Arno...@Arnold.com

"Bill" <...@d2g2000pra.googlegroups.com...

Flash a message "Please wait process may take a long time.....", set the
mouse pointer to an "hour glass" while processing, and set the mouse pointer
back to normal when the process is completed.

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4061 (20090507) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


On Fri, 8 May 2009 02:56:08 -0700, Morten Wennevik [C# MVP] <...@hotmail.com

Hi Bill,

Create the DataSource in a BackGroundWorker and make sure the DataSource is
sorted before adding it to the DataGridView. Use the
BackgroundWorker.ProgressChanged event (which is thread safe) or Invoke your
own methods when you need to display changes. Remember that lots of
events/invokes are expensive and may drastically slow the whole process down.
Keep a counter and only update if((counter % 1000) == 0) or similar. You
won't be able to report progress during the actual sorting unless you
implement your own sorting algorithm as Peter points out.

If you get the rows from a query, the fastest way would be to get the rows
presorted by doing the sorting as part of the query. If you need to sort it
afterwards sort it in the BackgroundWorker. If you need to use
DataGridView.Sort, implement paging and lower the number of rows displayed.

--
Happy Coding!
Morten Wennevik [C# MVP]

>

On Fri, 8 May 2009 13:19:01 -0700 (PDT), Bill <...@yahoo.com

On May 8, 3:56 am, Morten Wennevik [C# MVP]
<...@hotmail.com
I should have been clearer about the problem. I do not have a
datasource. the code adds rows to a datatable and I am using the
dataview to sort it. The problem is that once the dataview sort method
is invoked, it is essentiall a "black box" as I have no way of
knowing how long it will take or any way of reporting percentage
progress. I already am using the backgroundworker reportprogress
method and I change the counter to a "Sorting..." message, but the
sort takes a while and the task manager sometimes indicates the
application is not responding. One of the replies suggested faking it
and periodically displaying some kind of update message using the
reportprogress, and that appears to be the best strategy.

On Fri, 8 May 2009 15:39:10 -0700 (PDT), Pavel Minaev <...@gmail.com

On May 8, 1:19 pm, Bill <...@yahoo.com
This is still extremely strange. If your call to Sort is in the
BackgroundWorker worker thread, then you shouldn't get "application
not responding".

Otherwise, yes, the best you can do is one of those fake progress
indicators which just loop infinitely. Like Vista's busy mouse cursor.

On Sat, 9 May 2009 10:03:01 -0700, Morten Wennevik [C# MVP] <...@hotmail.com

Can't you add the DataRows presorted? If you sort the DataTable before
attaching it to a control, while still in the BackgroundWorker you should
still get a responsive client, yet you do not know the progress of the
sorting.

I suggest you create a business object representing the DataRow. Create a
list of these objects in memory and do the sorting against this list, and
then use this list as a DataSource in the DataGridView, or even better, use a
subset from this list. I still question the need for showing million items
in a list.

--
Happy Coding!
Morten Wennevik [C# MVP]

Discussion Title: Report progess during black box process
Title Keywords: Report  progess  during  black  process