473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PLEASE HELP MULTITHREADING VB.NET QUESTION

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 manualreseteven t 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 readerwriterloc k 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 readerwriterloc k 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
Nov 20 '05 #1
2 1664

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" <Th*******@TAKE OUTTHISSPAMBUST ERsofthome.net>
| 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: <eX************ **@TK2MSFTNGP09 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: 0-2pool154-247.nas16.nashv ille1.tn.us.da. qwest.net
65.144.154.247
| Path:
cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!cpm sftngxa09.phx.g bl!TK2MSFTNGP08 .
phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:177328
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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 manualreseteven t 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 readerwriterloc k 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 readerwriterloc k 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
|
|
|

Nov 20 '05 #2
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 [MSFT]" <CR*****@online .microsoft.com> wrote in message
news:aZ******** ******@cpmsftng xa07.phx.gbl...

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" <Th*******@TAKE OUTTHISSPAMBUST ERsofthome.net>
| 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: <eX************ **@TK2MSFTNGP09 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: 0-2pool154-247.nas16.nashv ille1.tn.us.da. qwest.net
65.144.154.247
| Path:
cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!cpm sftngxa09.phx.g bl!TK2MSFTNGP08 . phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:177328
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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 manualreseteven t 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 readerwriterloc k 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 readerwriterloc k 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
|
|
|

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1464
by: Jean-Yves Nief | last post by:
hello, I have written a script which is performing some tasks in multithreading mode: the main thread is opening a connection to a distant server and all the threads that I start will have to perform actions on the remote server using the connection initiated by the main thread. At first sight, the only way I could achieve that in a proper manner (ie without having to open a connection to the remote server in every single thread and...
1
2052
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able to kick off the process and continue to work in the appliaction while getting progress updates and the ability to cancel. The method that seems easiest to me is this: The class exposes certain events for progress. Start, ProgressUpdate, and...
0
275
by: GianGuz | last post by:
In the following example Global is able to create and manage access to objects of any kind (even in a multithreading environment) with and index value attached to. So a Global<0, string> is a unique string instance object allocated into the system that can be accessed from any point into the program simply 'creating' another instance of Global<int, T> with the same id and type.Like globals, destruction of these objects is delegated until...
11
4266
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate threads of a multithreaded program using embedded SQL. Since the threads do not need to share transaction scopes, the sqleAttachToCtx family of APIs do not seem to be necessary. <quote> In the default implementation of threaded applications against...
16
8506
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
2
2312
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and I just wanted to ask if I am missing anything based on the following scenario. My test app pulls data from a large external data source which has a table-like structure (but not rdbms - more
2
3842
by: Multithreading problem in vb.net | last post by:
Greetings, I am new to multithreading and I am trying to implement it in my app. This application is distributed application which needs to refresh every say 5 secs to show some activities in the datagrid. I have implemented querying the database in a separate thread and and then showing it in the datagrid in the UI thread. It all works fine and the datagrid gets updated every 5 secs. This happens in the desktop (Main form) of the...
55
3312
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to call operations on Controls from a delegate, otherwise it does not work. However each time I've done an operation, I must update the progressbar and progresslabel, but this cannot be done in the delegate as it does not work.
7
16311
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or Exceptional C++, for example). Platform-specific (e.g.: Win32, POSIX) is OK, as long as it's good :) Thank you, Ray
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.