BackGroundWorker for .NET 1.1?

  • Thread starter Thread starter Mitchell Vincent
  • Start date Start date
M

Mitchell Vincent

I just read my MSDN magazine from last month and was very pleased to see
an article about performance and the small(er) things you can do to
improve it.

I have a pretty big database driven winforms application that I've been
working on and am very disappointed in the time it takes to show some of
these windows. I am doing a lot of data binding and database access in
the form's loading event. I do SuspendLayout/ResumeLayout around the
code in my _load event but that really only makes it *appear* to "pop"
faster.

I read about .NET 2.0's BackgroundWorker support and was intrigued. I
can't afford the move to 2.0 yet as virtually no one has it installed,
so I'm looking for a solution that will work with .NET 1.1. Is starting
a new thread in the load event "proper"? In order to data bind I need to
run at least a SELECT query, so is there some harm in binding in a
thread other than the main one?

Obviously it does me no good to show a window that the user can't
interact with, but even shaving half a second off the load time would be
a substantial improvement. Even fractions of a second *appear* to be a
long time when just opening a window.
 
You need to create a seperate thread to load the data. Is this what you are
asking to do?
 
vbnetdev said:
You need to create a seperate thread to load the data. Is this what you are
asking to do?

Basically, yes, and asking if that is a good or bad idea (and why if
it's either!).

I want to display those forms as fast as possible but as soon as they
are displayed the user will want to interact with them. It makes sense
I'd load everything up *before* I show for form. Should I maybe move the
database work/binding to the window's class constructor?
 
Well there are a couple schools of thought on this. One of the advances of
VS 2005 is it attempts to have you use delegates so that your actions are
thread safe.

But what I will do is give you a link and let you decide.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q315577

load your dataset as you do normally in threadtask.

I load what i need and disable any interative capability until complete. I
load the data in another for appearance sake (to keep the form from
appearing like it is not responding) during this time. Of course then I
assign it ot the datagrid.

However.....

You will get an exception in VS2005 doing this as your datagrid will access
a thread that is not its owner. This can be disabled. But a study of
delegates will resolve this.
http://groups.google.com/group/micr...5d3077ceda3ac61?sa=X&oi=groupsr&start=1&num=3
 
Just wondering... Have you tested which part exactly takes such a long time?
Do you maybe have a client side cursor with a full table read?
 
Hi Mitchell,

Thanks for posting!

As other communicators mentioned, there are many ways to approach current
issue. If you want to implement the Backgroundworker in .NET 1.1, the
following article demonstrates how to implement the Backgroundworker in C
sharp:
http://weblogs.asp.net/rosherove/articles/BackgroundWorker.aspx

I hope this will be helpful!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006. Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 
Back
Top