PLEASE HELP MULTITHREADING VB.NET QUESTION

S

SStory

Here is the situation.

I want to display Icons, Type of file etc from a file extension.

Upon initial program load I may only need icons for certain files. But
other operations will require showing all filetypes and icons. I have an
object that has extension, desc (like Word Document) and then icon, which is
nothing to start with.

I have a collection object of these and when it is initialized it goes to
the registry to get all extensions registered and their file type desc.
automatically (this is very fast) the collection has a hashtable for
lookups although items are stored in the collection derived from
collectionbase.

Getting the icons for each of these (647 on my system) takes 14-28
seconds--eternity for users.

So I wanted to make a background thread that starts before my splash
screen--or at some time and starts going through the collection 0....N
calling a method on the class in the collection to tell it to get its
associated icon.

However, should I need x specific icons before this process terminates I
would like to be able to tell the thread to either pause or save current
index, stop that and use another method to go get ".exe,.doc,.zip" or
whatever limited list I immediately need.

I am really confused as to how to go about this. I have read the WROX
professional book on Threading and have a basic understanding.

I have my own app class that is accesible to the entire application and my
FileInfo collection is part of it.

Questions:

1.) How do I have a thread getting these, yet access the ones I need if I
need some before it gets finished?
Do I launch the thread and let it populate this collection and then
call a method in that thread to say pause and get these and return them as a
separate mini collection? (but the apps collection would be running in a
separate thread.)

Or do I tell the thread to fill up its own private version of the collection
and when done pass that to the app object which will overwrite it's own
object? If so how? I was planning to use the manualresetevent which will
allow thread pausing. How would I then tell it to get what I need at
present? Would I have a method in the thread to call passing what I need
and it send back the collection as is including those items that I told it
to get and me overwrite the master collection in my app object? And would I
need a readerwriterlock in the app for the collection? Seems I would?

Also since the app could want to access it's collection at any time(being
called from my program to get that collection) do I somehow need to sync its
access?

I am close to understanding but missing something.

Could anyone please help me get this straight and tell me what is the best
way to do it?

Seems that if I need a readerwriterlock in my app object for dealing with
when the collection of fileinfo is accessed, that if it can be read then I
don't need to worry about the collection internal Item method having sync
problems?

What issues am I missing and how?

Thanks,

Shane
 
V

Vladimir Sadov [MSFT]

As I understand correctly you want your background thread to do some work
contunuously and when you need something in particular you want to
communicate with the thread somehow.

This is more a design, not a language question. To tell the thread to do
something else is relatively easy - the thread needs to check some flag
whether what it is currently doing is ok or it needs to do something else.
To tell the foreground thread that the background thread is done is
slightly harder

1. background thread: runs in some loop and checks fo some flag to be set
2. when foreground thread needs something it fills some task description
variable (could be a collection of icon names for example) and sets the
flag and locks itself on an event.
3. background thread discovers that the flag is set. It reads the task
description, completes the tasks or makes sure the tasks are done, resets
the event and continues doing its background work
4. foreground thread after being released picks the results and continues.

Thanks,
Vladimir [VB.Net team]


-------------------
| From: "SStory" <[email protected]>
| Subject: PLEASE HELP MULTITHREADING VB.NET QUESTION
| Date: Thu, 29 Jan 2004 15:41:16 -0600
| Lines: 73
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 0-2pool154-247.nas16.nashville1.tn.us.da.qwest.net
65.144.154.247
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:177328
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Here is the situation.
|
| I want to display Icons, Type of file etc from a file extension.
|
| Upon initial program load I may only need icons for certain files. But
| other operations will require showing all filetypes and icons. I have an
| object that has extension, desc (like Word Document) and then icon, which
is
| nothing to start with.
|
| I have a collection object of these and when it is initialized it goes to
| the registry to get all extensions registered and their file type desc.
| automatically (this is very fast) the collection has a hashtable for
| lookups although items are stored in the collection derived from
| collectionbase.
|
| Getting the icons for each of these (647 on my system) takes 14-28
| seconds--eternity for users.
|
| So I wanted to make a background thread that starts before my splash
| screen--or at some time and starts going through the collection 0....N
| calling a method on the class in the collection to tell it to get its
| associated icon.
|
| However, should I need x specific icons before this process terminates I
| would like to be able to tell the thread to either pause or save current
| index, stop that and use another method to go get ".exe,.doc,.zip" or
| whatever limited list I immediately need.
|
| I am really confused as to how to go about this. I have read the WROX
| professional book on Threading and have a basic understanding.
|
| I have my own app class that is accesible to the entire application and my
| FileInfo collection is part of it.
|
| Questions:
|
| 1.) How do I have a thread getting these, yet access the ones I need if I
| need some before it gets finished?
| Do I launch the thread and let it populate this collection and then
| call a method in that thread to say pause and get these and return them
as a
| separate mini collection? (but the apps collection would be running in a
| separate thread.)
|
| Or do I tell the thread to fill up its own private version of the
collection
| and when done pass that to the app object which will overwrite it's own
| object? If so how? I was planning to use the manualresetevent which will
| allow thread pausing. How would I then tell it to get what I need at
| present? Would I have a method in the thread to call passing what I need
| and it send back the collection as is including those items that I told it
| to get and me overwrite the master collection in my app object? And
would I
| need a readerwriterlock in the app for the collection? Seems I would?
|
| Also since the app could want to access it's collection at any time(being
| called from my program to get that collection) do I somehow need to sync
its
| access?
|
| I am close to understanding but missing something.
|
| Could anyone please help me get this straight and tell me what is the best
| way to do it?
|
| Seems that if I need a readerwriterlock in my app object for dealing with
| when the collection of fileinfo is accessed, that if it can be read then I
| don't need to worry about the collection internal Item method having sync
| problems?
|
| What issues am I missing and how?
|
| Thanks,
|
| Shane
|
|
|
 
S

SStory

Thanks Vladimir, for the reply.

I decided to create a background thread which gets a copy of the collection
to be populated, which contains all file extensions in the registry, and let
the background thread start populating... If I need specific icons before it
gets through I pass in a list of them and the thread stops the normal
operation and gets those immediately, passing back the collection after
finishing, then continues getting all icons where it left off.

It appears that this is going to work.

My real confusions was how to access the collection in the bg thread and
from the main thread, but the answer seems to be, make a copy first and let
the background thread populate a copy.

Thanks again,

Shane
Vladimir Sadov said:
As I understand correctly you want your background thread to do some work
contunuously and when you need something in particular you want to
communicate with the thread somehow.

This is more a design, not a language question. To tell the thread to do
something else is relatively easy - the thread needs to check some flag
whether what it is currently doing is ok or it needs to do something else.
To tell the foreground thread that the background thread is done is
slightly harder

1. background thread: runs in some loop and checks fo some flag to be set
2. when foreground thread needs something it fills some task description
variable (could be a collection of icon names for example) and sets the
flag and locks itself on an event.
3. background thread discovers that the flag is set. It reads the task
description, completes the tasks or makes sure the tasks are done, resets
the event and continues doing its background work
4. foreground thread after being released picks the results and continues.

Thanks,
Vladimir [VB.Net team]


-------------------
| From: "SStory" <[email protected]>
| Subject: PLEASE HELP MULTITHREADING VB.NET QUESTION
| Date: Thu, 29 Jan 2004 15:41:16 -0600
| Lines: 73
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 0-2pool154-247.nas16.nashville1.tn.us.da.qwest.net
65.144.154.247
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:177328
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Here is the situation.
|
| I want to display Icons, Type of file etc from a file extension.
|
| Upon initial program load I may only need icons for certain files. But
| other operations will require showing all filetypes and icons. I have an
| object that has extension, desc (like Word Document) and then icon, which
is
| nothing to start with.
|
| I have a collection object of these and when it is initialized it goes to
| the registry to get all extensions registered and their file type desc.
| automatically (this is very fast) the collection has a hashtable for
| lookups although items are stored in the collection derived from
| collectionbase.
|
| Getting the icons for each of these (647 on my system) takes 14-28
| seconds--eternity for users.
|
| So I wanted to make a background thread that starts before my splash
| screen--or at some time and starts going through the collection 0....N
| calling a method on the class in the collection to tell it to get its
| associated icon.
|
| However, should I need x specific icons before this process terminates I
| would like to be able to tell the thread to either pause or save current
| index, stop that and use another method to go get ".exe,.doc,.zip" or
| whatever limited list I immediately need.
|
| I am really confused as to how to go about this. I have read the WROX
| professional book on Threading and have a basic understanding.
|
| I have my own app class that is accesible to the entire application and my
| FileInfo collection is part of it.
|
| Questions:
|
| 1.) How do I have a thread getting these, yet access the ones I need if I
| need some before it gets finished?
| Do I launch the thread and let it populate this collection and then
| call a method in that thread to say pause and get these and return them
as a
| separate mini collection? (but the apps collection would be running in a
| separate thread.)
|
| Or do I tell the thread to fill up its own private version of the
collection
| and when done pass that to the app object which will overwrite it's own
| object? If so how? I was planning to use the manualresetevent which will
| allow thread pausing. How would I then tell it to get what I need at
| present? Would I have a method in the thread to call passing what I need
| and it send back the collection as is including those items that I told it
| to get and me overwrite the master collection in my app object? And
would I
| need a readerwriterlock in the app for the collection? Seems I would?
|
| Also since the app could want to access it's collection at any time(being
| called from my program to get that collection) do I somehow need to sync
its
| access?
|
| I am close to understanding but missing something.
|
| Could anyone please help me get this straight and tell me what is the best
| way to do it?
|
| Seems that if I need a readerwriterlock in my app object for dealing with
| when the collection of fileinfo is accessed, that if it can be read then I
| don't need to worry about the collection internal Item method having sync
| problems?
|
| What issues am I missing and how?
|
| Thanks,
|
| Shane
|
|
|
 

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

Top