473,715 Members | 6,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unique copy of DLL

Hi,

I have written a Class Library in VB.net which provides Props/Meths to a
caller to hide the uglinesses of a TCP message protocol between a Client
and a Server.

All this works just fine.

Now I am trying to develop a LOAD TESTER app which spawns lotso' threads
each with this capability to bang the server.

The problerm is that the DLL class which worked just fine in a single
instance runs into problems because each version of the client-threads
seems to be reaching into the SAME copy of the DLL.

Everything I've read tells me to wrap the DLL areas that deal with
variables in SyncLocks... but this is NOT what I want... The DLL is NOT
STATELESS and so each new thread needs to have ITS OWN UNIQUE COPY of the
dll and its variables.

So the question is How Do I instantiate the DLL (class) in the thread to
ensure that it gets a NEW UNIQUE COPY running?

BTW, currently NONE of the Class's variables are public (though the
Props/Meths must be.) And the class DOES attempt to create a new copy
using...

Dim myDLLCls as theDLLClass
myDLLCls = New theDLLClass
but this does NOT generate a NEW copy in this thread.

Help !

regards,
tob
Nov 25 '06 #1
12 1560


"tony obrien" <tob_@_sourceco de-inc.comwrote in message
news:Xn******** *************** **********@130. 81.64.196...
Hi,

I have written a Class Library in VB.net which provides Props/Meths to a
caller to hide the uglinesses of a TCP message protocol between a Client
and a Server.

All this works just fine.

Now I am trying to develop a LOAD TESTER app which spawns lotso' threads
each with this capability to bang the server.

The problerm is that the DLL class which worked just fine in a single
instance runs into problems because each version of the client-threads
seems to be reaching into the SAME copy of the DLL.

Everything I've read tells me to wrap the DLL areas that deal with
variables in SyncLocks... but this is NOT what I want... The DLL is NOT
STATELESS and so each new thread needs to have ITS OWN UNIQUE COPY of the
dll and its variables.
. . .
That's just a design problem. If each client needs its own data, don't put
that data in shared scope. Create a class for each client to own, and place
that client's state data in the instance state of that class.

David

Nov 25 '06 #2
"David Browne" <davidbaxterbro wne no potted me**@hotmail.co mwrote in
news:#G******** ******@TK2MSFTN GP02.phx.gbl:
>

"tony obrien" <tob_@_sourceco de-inc.comwrote in message
news:Xn******** *************** **********@130. 81.64.196...
>Hi,

I have written a Class Library in VB.net which provides Props/Meths
to a caller to hide the uglinesses of a TCP message protocol between
a Client and a Server.

All this works just fine.

Now I am trying to develop a LOAD TESTER app which spawns lotso'
threads each with this capability to bang the server.

The problerm is that the DLL class which worked just fine in a single
instance runs into problems because each version of the
client-threads seems to be reaching into the SAME copy of the DLL.

Everything I've read tells me to wrap the DLL areas that deal with
variables in SyncLocks... but this is NOT what I want... The DLL is
NOT STATELESS and so each new thread needs to have ITS OWN UNIQUE
COPY of the dll and its variables.
. . .

That's just a design problem. If each client needs its own data,
don't put that data in shared scope. Create a class for each client
to own, and place that client's state data in the instance state of
that class.

David

Thanks, David...

I do not disagree BUT what seems counter intuitive is that if I were to
take the SOURCE of the DLL and include it (as a class) to the project and
let each new thread create its copy of that class it, each thread WOULD
have its own, unique copy of the data and variables... but if I create
the class separately as a DLL I CAN NOT get a unique copy??

It seems you are suggesting that Multithreaded DLLs are ALWAYS shared and
can not operate a state machines. Seems like a HUGE whole a development
capability.

tob
Nov 25 '06 #3


"tony obrien" <tob_@_sourceco de-in.comwrote in message
news:Xn******** *************** **********@130. 81.64.196...
"David Browne" <davidbaxterbro wne no potted me**@hotmail.co mwrote in
news:#G******** ******@TK2MSFTN GP02.phx.gbl:
>>

"tony obrien" <tob_@_sourceco de-inc.comwrote in message
news:Xn******* *************** ***********@130 .81.64.196...
>>Hi,

I have written a Class Library in VB.net which provides Props/Meths
to a caller to hide the uglinesses of a TCP message protocol between
a Client and a Server.

All this works just fine.

Now I am trying to develop a LOAD TESTER app which spawns lotso'
threads each with this capability to bang the server.

The problerm is that the DLL class which worked just fine in a single
instance runs into problems because each version of the
client-threads seems to be reaching into the SAME copy of the DLL.

Everything I've read tells me to wrap the DLL areas that deal with
variables in SyncLocks... but this is NOT what I want... The DLL is
NOT STATELESS and so each new thread needs to have ITS OWN UNIQUE
COPY of the dll and its variables.
. . .

That's just a design problem. If each client needs its own data,
don't put that data in shared scope. Create a class for each client
to own, and place that client's state data in the instance state of
that class.

David


Thanks, David...

I do not disagree BUT what seems counter intuitive is that if I were to
take the SOURCE of the DLL and include it (as a class) to the project and
let each new thread create its copy of that class it, each thread WOULD
have its own, unique copy of the data and variables... but if I create
the class separately as a DLL I CAN NOT get a unique copy??
Yes you can. There are nested scopes in which you can declare state. You
are talking about the outermost scope: class scope. Each class you define
has a class scope (aka global, shared, static). Variables declared in this
scope, or reachable from a variable in this scope are shared among all
callers in the App Domain.

Variables declared or reachable from instance variables of a type created
separately for each client won't be shared.
It seems you are suggesting that Multithreaded DLLs are ALWAYS shared and
can not operate a state machines. Seems like a HUGE whole a development
capability.
No not at all. You can have any mix of sharing and separation of state you
want.

David

Nov 25 '06 #4
tony obrien <tob_@_sourceco de-inc.comwrote:
I have written a Class Library in VB.net which provides Props/Meths to a
caller to hide the uglinesses of a TCP message protocol between a Client
and a Server.

All this works just fine.

Now I am trying to develop a LOAD TESTER app which spawns lotso' threads
each with this capability to bang the server.

The problerm is that the DLL class which worked just fine in a single
instance runs into problems because each version of the client-threads
seems to be reaching into the SAME copy of the DLL.
Firstly, you need to differentiate between "DLL" and "class". They're
not the same thing at all, and you seem to be treating them
interchangably.

It's fine to have one DLL, but it sounds like you probably want each
thread to have its own instance of your class. So long as none of your
variables are Shared, you should then be okay.

If that doesn't help, could you post a short but complete program which
demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 25 '06 #5
Jon Skeet [C# MVP] <sk***@pobox.co mwrote in
news:MP******** *************** *@msnews.micros oft.com:
tony obrien <tob_@_sourceco de-inc.comwrote:
>I have written a Class Library in VB.net which provides Props/Meths
to a caller to hide the uglinesses of a TCP message protocol between
a Client and a Server.

All this works just fine.

Now I am trying to develop a LOAD TESTER app which spawns lotso'
threads each with this capability to bang the server.

The problerm is that the DLL class which worked just fine in a single
instance runs into problems because each version of the
client-threads seems to be reaching into the SAME copy of the DLL.

Firstly, you need to differentiate between "DLL" and "class". They're
not the same thing at all, and you seem to be treating them
interchangably.

It's fine to have one DLL, but it sounds like you probably want each
thread to have its own instance of your class. So long as none of your
variables are Shared, you should then be okay.

If that doesn't help, could you post a short but complete program
which demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
Thanks...

In this particular case I use them interchangeably since I created a DLL
from a single Class with nothing but private variables and public
Properties and Methods.... in my mind the Class is the DLL is the Class.

sorry for the confusion.

Recently I tried bringing that class (that created the DLL) into my test
program and it still does not operate after a 2nd or 3rd thread is begun...
so perhaps I have some deeper issues going on than I thought.

I am trying to get to the smallest thing that I know has the problem.
Nov 26 '06 #6
tony obrien <to**@sourcecod e-inc.comwrote:
In this particular case I use them interchangeably since I created a DLL
from a single Class with nothing but private variables and public
Properties and Methods.... in my mind the Class is the DLL is the Class.

sorry for the confusion.
No problem - but I think it's worth keeping the difference clear in
your head (and in your code and comments) as you never know when you'll
need another class in the same assembly.
Recently I tried bringing that class (that created the DLL) into my test
program and it still does not operate after a 2nd or 3rd thread is begun...
so perhaps I have some deeper issues going on than I thought.

I am trying to get to the smallest thing that I know has the problem.
I'm sure that when we've got a small sample we'll be able to make
progress.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 26 '06 #7
tony obrien <to**@sourcecod e-inc.comwrote in
news:Xn******** *************** **********@130. 81.64.196:
Jon Skeet [C# MVP] <sk***@pobox.co mwrote in
news:MP******** *************** *@msnews.micros oft.com:
Hi Jon, (I very much appreciate your taking the time and energy to help
me thru this !)
I have been able to at least determine how the problem exhibits itself...
the very bottom has this explanation.

Below are some snippets to give you an idea of how this load tester
client operates....(an d yes I have left out gobs of code as to not bore
(overwhelm !) you... but remember this all works as a single instance so
I propose that it is in the 'multithreaded-ness' of it.)
------- IN MAIN:

'Create a new instance of the tcp interface class
aSession = New serviceConnecti on

'create a new thread
serverListenerT hread = New Threading.Threa d(AddressOf
aSession.startT hisThread)

'I then start the thread....
serverListenerT hread.Start()
------ IN THE SERVICECONNECTI ON CLASS:

=============== =============== =======
Private clientService as TCPClient
Private Event OnLineReceived( ByVal sender As serviceConnecti on, ByVal
Data() As Byte, ByVal theBytesReadCou nt As Integer)

=============== =============== =======
Public Sub StartThisThread ()

' Create an event handler to allow this serviceconnecti on class to
communicate
AddHandler OnLineReceived, AddressOf OnLineReceivedS ervice

Try
clientService = New TcpClient(mySer verNameStr$,
mSessionPortNum ber)

clientService.G etStream.BeginR ead(readBuffer, 0,
READ_BUFFER_SIZ E, AddressOf ServiceStreamRe ceiver, Nothing)
SOM = True

Catch Ex As Exception
mlastErrorStrin g = Ex.Message
Exit Sub
End Try

'Now I sit in a loop asking the SERVER for various services
=============== =============== ========
Private Sub ServiceStreamRe ceiver(ByVal ar As IAsyncResult)

Try
' Ensure that no other threads try to use the stream at the
same time.
SyncLock client.GetStrea m
' Finish asynchronous read into readBuffer and get number
of bytes read.
LCBytesRead = client.GetStrea m.EndRead(ar)
End SyncLock

RaiseEvent OnLineReceived( Me, readBuffer, LCBytesRead)

' Ensure that no other threads try to use the stream at the
same time.
SyncLock client.GetStrea m
' Start a new asynchronous read into readBuffer.
LCBytesRead = 0
client.GetStrea m.BeginRead(rea dBuffer, 0,
READ_BUFFER_SIZ E, AddressOf ServiceStreamRe ceiver, Nothing)
End SyncLock

Catch e As Exception

End Try
End Sub
=============== =============== ========

Private Sub OnLineReceivedS ervice(ByVal thisServiceConn ection As
serviceConnecti on, ByVal data() As Byte, ByVal theBytesReadCou nt As
Integer)

'This is the EVENT raised by ServiceStreamRe ceiver above....

'It gets passed the "instance" of the connection, the bytecount and
data... and this routine operates on the data.
=============== =============== ========
=============== =============== ========
=============== =============== ========

OK, so what happens is that when I start the 2nd or 3rd thread the
OnLineReceivedS ervice callback will get passed the "wrong instance" on
some response message that was received (recall that there are supposedly
distinct "thisServiceCon nection" classes created and "started".. .) and so
some instance is waiting for a response it never gets... and the instance
that does get passed throws the message away because it wasn't meant for
him.

This implies that the "wrong" instance of ServiceStreamHa ndler is being
called... perhaps the TCP.net stuff I am using does not allow me to do
what I am trying to do?

regards,
tob
Nov 27 '06 #8
With all due respect, Tony, do you have multiple threads each listening for
data on the same TCP port?

If this were the case, I fail to see how you could PREVENT contention.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"tony obrien" <tob_@_sourceco de-inc.comwrote in message
news:Xn******** *************** *********@130.8 1.64.196...
tony obrien <to**@sourcecod e-inc.comwrote in
news:Xn******** *************** **********@130. 81.64.196:
>Jon Skeet [C# MVP] <sk***@pobox.co mwrote in
news:MP******* *************** **@msnews.micro soft.com:
Hi Jon, (I very much appreciate your taking the time and energy to help
me thru this !)
I have been able to at least determine how the problem exhibits itself...
the very bottom has this explanation.

Below are some snippets to give you an idea of how this load tester
client operates....(an d yes I have left out gobs of code as to not bore
(overwhelm !) you... but remember this all works as a single instance so
I propose that it is in the 'multithreaded-ness' of it.)
------- IN MAIN:

'Create a new instance of the tcp interface class
aSession = New serviceConnecti on

'create a new thread
serverListenerT hread = New Threading.Threa d(AddressOf
aSession.startT hisThread)

'I then start the thread....
serverListenerT hread.Start()
------ IN THE SERVICECONNECTI ON CLASS:

=============== =============== =======
Private clientService as TCPClient
Private Event OnLineReceived( ByVal sender As serviceConnecti on, ByVal
Data() As Byte, ByVal theBytesReadCou nt As Integer)

=============== =============== =======
Public Sub StartThisThread ()

' Create an event handler to allow this serviceconnecti on class to
communicate
AddHandler OnLineReceived, AddressOf OnLineReceivedS ervice

Try
clientService = New TcpClient(mySer verNameStr$,
mSessionPortNum ber)

clientService.G etStream.BeginR ead(readBuffer, 0,
READ_BUFFER_SIZ E, AddressOf ServiceStreamRe ceiver, Nothing)
SOM = True

Catch Ex As Exception
mlastErrorStrin g = Ex.Message
Exit Sub
End Try

'Now I sit in a loop asking the SERVER for various services
=============== =============== ========
Private Sub ServiceStreamRe ceiver(ByVal ar As IAsyncResult)

Try
' Ensure that no other threads try to use the stream at the
same time.
SyncLock client.GetStrea m
' Finish asynchronous read into readBuffer and get number
of bytes read.
LCBytesRead = client.GetStrea m.EndRead(ar)
End SyncLock

RaiseEvent OnLineReceived( Me, readBuffer, LCBytesRead)

' Ensure that no other threads try to use the stream at the
same time.
SyncLock client.GetStrea m
' Start a new asynchronous read into readBuffer.
LCBytesRead = 0
client.GetStrea m.BeginRead(rea dBuffer, 0,
READ_BUFFER_SIZ E, AddressOf ServiceStreamRe ceiver, Nothing)
End SyncLock

Catch e As Exception

End Try
End Sub
=============== =============== ========

Private Sub OnLineReceivedS ervice(ByVal thisServiceConn ection As
serviceConnecti on, ByVal data() As Byte, ByVal theBytesReadCou nt As
Integer)

'This is the EVENT raised by ServiceStreamRe ceiver above....

'It gets passed the "instance" of the connection, the bytecount and
data... and this routine operates on the data.
=============== =============== ========
=============== =============== ========
=============== =============== ========

OK, so what happens is that when I start the 2nd or 3rd thread the
OnLineReceivedS ervice callback will get passed the "wrong instance" on
some response message that was received (recall that there are supposedly
distinct "thisServiceCon nection" classes created and "started".. .) and so
some instance is waiting for a response it never gets... and the instance
that does get passed throws the message away because it wasn't meant for
him.

This implies that the "wrong" instance of ServiceStreamHa ndler is being
called... perhaps the TCP.net stuff I am using does not allow me to do
what I am trying to do?

regards,
tob

Nov 28 '06 #9
"Nick Malik [Microsoft]" <ni*******@hotm ail.nospam.comw rote in
news:k4******** *************** *******@comcast .com:
With all due respect, Tony, do you have multiple threads each
listening for data on the same TCP port?

If this were the case, I fail to see how you could PREVENT contention.
Hi Nick,

Well,er, yeah but (ye old "yeah butt" !)

I was trying to mimic what a web browser does... my thought was that I
"publish" a known TCP port number (in this case 10,000)... clients connect
to that port number, the SERVER creates a listener for this new connection
in a new thread and starts that thread, then goes back to waiting for a new
connection on 10,000.

My understanding was that the TCP stack magically re-casts the "accepted"
client into a new internal port number and carries the conversation on
(somehow) correctly all the while. And to me this is akin to magic, but
how else *could* a server operate (such as a web browser with ONE KNOWN
port #80.)

Your thoughts?
tob
Nov 28 '06 #10

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

Similar topics

2
2301
by: kevin parks | last post by:
hi. I've been banging my head against this one a while and have asked around, and i am throwing this one out there in the hopes that some one can shed some light on what has turned out to be a tough problem for me (though i am getting closer). i have been mucking with a lot of data in a dictionary that looks like:
3
5208
by: LELAND PRINCE | last post by:
Thanks, this group has been a big help. I need to create a backup copy of a working file that changes everyday, but I need to maintain a copy from each day. Would like to create: back1.txt back2.txt .. ..
0
2036
by: J.D. Buehls | last post by:
I have an .asp page with a form to copy job responsibilites form one job to another. It is a hotmail type interface with checkboxes besides each responsibility. After submitting, it should copy the selected resp's to a different job. After that it should renumber that job's responsibilities. This is the code I am using now to copy: copySQL4 = "INSERT INTO jambue.RESP(POSCODE,IDCODE1,IDCODE2,RESP_NUM,RESP) SELECT '" & id & "'...
26
45431
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.) How can I achieve this? I suppose I would get the most-hated "table/view is changing, trigger/function may not see it" error if I tried to write a trigger that checks the uniqueness of non-null values upon insert/update.
22
2756
by: Claudio Jolowicz | last post by:
Is it possible to store unique objects in an STL container? Suppose an object of class C is unique: class C { public: C() {} ~C() {} private:
2
7826
by: SJM | last post by:
I have a report that displays records of real estate properties. It is possible for each property to appear a number of times for various reasons. Each record however is unique. What I would like to do is display the total of the number of unique properties in the report footer, not just a count of the number of records. I have experimented with grouping on the property field and using running sums but to no avail. I have also tried to...
29
3752
by: Lauren Wilson | last post by:
Does anyone know how the following info is extracted from the user's computer by a Front Page form? HTTP User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 I only ask because I believe I could use the same info as part of a scheme to generate a unique (or at least less common) serialized id code for the user's computer as part of a software locking and activation system. If I had a DLL...
2
1402
by: Peter Oliphant | last post by:
Sometimes it's hard to get straight when passing or storing or returning an instance of a class whether you are still dealing with the original object or a copy. For example, the '=' operator used on pointers to two instance of a class can be overloaded to return the pointer to the target instance or a pointer to a copy of the target instance. When passing an instance of a class it can be done so the method will manipulate the instance...
15
37596
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code Different-2 string.
0
8718
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
9343
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...
1
9104
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
9047
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
6646
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
5967
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();...
0
4477
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...
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.