473,698 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on threading and using P/Invoke...

If a DLL has been created to be thread-safe, and you create a wrapper
class around it in C# that is non-static (i.e. you must instantiate
objects from it), what are the implications of creating multiple objects
from said wrapper class? There's only one DLL, so is it creating
multiple instances of its functions when each object is making calls to
it? Does anyone know of any resources that explain this? Thanks, gilad
Nov 16 '05 #1
4 2061
giliad,

There is no implication. Your class is going to be a wrapper around the
calls to the DLL, and you are probably going to pass something like a
handle, which will represent the data the function needs to operate on. The
DLL function will be responsible for handling concurrency. You only have to
worry about concurrency in the wrapper level (locking access to the handle,
for example).

As for multiple instance of the dll, this isn't the case. The dll will
be loaded once for the process, and that's it. Functions are not loaded
every time they are called, rather, they are mapped to the process space
until unloaded. So in this case, the function is loaded once, but is being
called in multiple places.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<gi***@arbinger sysBADSPAMBOT.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
If a DLL has been created to be thread-safe, and you create a wrapper
class around it in C# that is non-static (i.e. you must instantiate
objects from it), what are the implications of creating multiple objects
from said wrapper class? There's only one DLL, so is it creating multiple
instances of its functions when each object is making calls to it? Does
anyone know of any resources that explain this? Thanks, gilad

Nov 16 '05 #2
Nicholas Paldino [.NET/C# MVP] wrote:
As for multiple instance of the dll, this isn't the case. The dll will
be loaded once for the process, and that's it. Functions are not loaded
every time they are called, rather, they are mapped to the process space
until unloaded. So in this case, the function is loaded once, but is being
called in multiple places.


I guess this is where I don't understand it. The DLL is loaded, and if
its function is executing for ObjectA of the wrapper (let's say it's
reading a long file and converting it), and a thread begins to execute
the second object, ObjectB of the wrapper, that calls that same function
of the DLL, what happens at this point? Does ObjectB get blocked until
the call from ObjectA finishes? Or is something else happening?

Sorry if I'm not clear in explaining this. I am using P/Invoke to call a
DLL to do some file conversions, and I want to make sure I've dotted my
i's and crossed my t's so to speak.
Nov 16 '05 #3
gilad,

Generally speaking, the functions are self contained (or at least, they
should be). It is possible that the functions access information that is
shared in the DLL, and in that case, the functions inside the dll have to
worry about thread concurrency (or maybe you do, if it is coded badly).
However, if you are not really altering any state that is stored in the DLL,
then you don't need to anything for concurrency, as each function call will
get its own stack space in the separate threads, and only work on variables
in that stack space.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<gi***@arbinger sysBADSPAMBOT.c om> wrote in message
news:eJ******** ******@TK2MSFTN GP12.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
As for multiple instance of the dll, this isn't the case. The dll
will be loaded once for the process, and that's it. Functions are not
loaded every time they are called, rather, they are mapped to the process
space until unloaded. So in this case, the function is loaded once, but
is being called in multiple places.


I guess this is where I don't understand it. The DLL is loaded, and if its
function is executing for ObjectA of the wrapper (let's say it's reading a
long file and converting it), and a thread begins to execute the second
object, ObjectB of the wrapper, that calls that same function of the DLL,
what happens at this point? Does ObjectB get blocked until the call from
ObjectA finishes? Or is something else happening?

Sorry if I'm not clear in explaining this. I am using P/Invoke to call a
DLL to do some file conversions, and I want to make sure I've dotted my
i's and crossed my t's so to speak.

Nov 16 '05 #4
Nicholas Paldino [.NET/C# MVP] wrote:
Generally speaking, the functions are self contained (or at least, they
should be). It is possible that the functions access information that is
shared in the DLL, and in that case, the functions inside the dll have to
worry about thread concurrency (or maybe you do, if it is coded badly).
However, if you are not really altering any state that is stored in the DLL,
then you don't need to anything for concurrency, as each function call will
get its own stack space in the separate threads, and only work on variables
in that stack space.


I appreciate your help.
Nov 16 '05 #5

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

Similar topics

5
1214
by: Alvin Bruney | last post by:
I dispensed some advice and its bugging me that it may not be 100% accurate. Worker threads should not touch main thread objects. Everybody knows that but if you pass a reference to a form object to a worker thread and you touch that form on the worker thread. All is well. Is that right? Will all really be well? It's a reference to the form object. The worker thread is still modifying the main threads object, reference or not, without...
9
1593
by: Edward | last post by:
Hello I hope someone could help me I'm trying to prevent code from running before the thread I created completes. Here's the code snippet DataTransformerWorker dtw = new DataTransformerWorker(strApplicationFolder, strSupplier strFile, lblProgress, ProgressBar1) //create new threa ThreadStart tdStart = new ThreadStart(dtw.StartProcess)
8
8193
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd party COM component that takes about 5 seconds to run one of its functions (Network IO bound call). Since I dont want my GUI to freeze
6
2873
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
3
1138
by: M O J O | last post by:
Hi, I have a little test project. I spin up a thread, lets it sleep for a second and then the thread makes a button visible ... or at least should make it visible, which it doesn't do. --------------------------------------------------------------------------- Here's my thread class:
0
2953
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
2
1264
by: Viet | last post by:
I have an architectural issue that I have been working on for quite awhile now and I would like another person's point of view. This issue involves the conversion of a VB6 app to VB.NET. In this VB6 app, the original programmer used 5 timers to periodically scan a document, process it, and display thumbnail images of the scanned document. These 5 timers implement 5 different subroutines that enable this process. In my conversion of this...
25
2504
by: MuZZy | last post by:
Hi, I'm currently rewriting some functionality which was using multithredaing for retrieving datasets from database and updating a grid control. I found that the grids (Infragistics UltraGrid, though it doesn't matter) were updated (i.e. grid.DataSource = dsDataSet;) and used for different purposes in the worker thread, so now i'm wrapping all those calls to grid's methods thru invoking which is a pain in the a$$ considering number of...
3
252
by: fiefie.niles | last post by:
I am using a thread. Inside the thread there is a sub ThreadMain. I am calling the thread from the main program MainForm. Inside the thread, if I am calling a sub (say doProcess) from the MainForm, does it mean that doProcess is processed inside or outside the thread ? Code from MainForm: Public Class MainForm Private Session As ClientSession = Nothing Private WorkerThread As Threading.Thread = Nothing
7
2374
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
0
8678
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
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
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
9030
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
8899
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
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6525
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
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2007
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.