473,573 Members | 3,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ActiveX / Threads question

Short question:
What's the difference between SingleUse and MultiUse ?

Long question:
I've been writing some sample code to see how different Instancing
values and threading models work. I tried all main combinations of
Instancing (Multiuse/Singleuse) and of Threading models (per
object/pool). Here's what I found:

MultiUse - Thread per Object
One new object for each request

SingleUse - Thread per Object
One new object for each request

MultiUse - Thread Pool (w/ 1 thread)
One object reused by all requests

SingleUse - Thread Pool (w/ 1 thread)
One new object for each request

The SU seems to be 100% superfluous: not only changing thread model
does not change the way it works, but whatever it does, it's exaclty
what MU does!

In order to test, I have created an ActiveXEXE with a form (frmTest)
and two classes (instancing is MU for one and SU for the other), both
have the same public method:

Public Sub Show(ByVal FormCaption As String, Top As Long, Left As
Long)
With frmTest
'First time show
If Not .Visible Then
.Top = Top
.Left = Left
.Visible = True
DoEvents
End If
.Caption = .Caption & FormCaption
End With
End Sub

The client calls this with something like:

Dim MUServ As New ActiveXServerEX E.MultiUseClass
Call MUServ.Show(Ind ex & " - " & Time, Top, Left + Width)

[Don't worry about the Top/Left stuff, it's irrelevant for this
discussion]

Can anybody shed some light on this topic once and for all ?

Thanks!
AK
Jul 17 '05 #1
8 4550

"AnalogKid" <AnalogKid17@(m ore_than_warm)m ail.com> wrote in message
news:mq******** *************** *********@4ax.c om...
| Short question:
| What's the difference between SingleUse and MultiUse ?
|
| Long question:
| I've been writing some sample code to see how different Instancing
| values and threading models work. I tried all main combinations of
| Instancing (Multiuse/Singleuse) and of Threading models (per
| object/pool). Here's what I found:
|
| MultiUse - Thread per Object
| One new object for each request

Each object is created by the same instance of the activex.exe. If there
is a module in the activex.exe with public data, all of the objects
could see that data, even if they are created by different applications.
Each object has its own thread.

|
| SingleUse - Thread per Object
| One new object for each request
|
Each object is created by a new instance of the activex.exe. Each object
can see public data only in its own instance of the activex.exe. Each
object has its own thread (actually, each has its own process).

| MultiUse - Thread Pool (w/ 1 thread)
| One object reused by all requests
|

Not quite. Actually nearly the same as MultiUse Thread/Object, except
that all the objects will be serviced using the same thread. You can
still create multiple, discreet objects.

| SingleUse - Thread Pool (w/ 1 thread)
| One new object for each request
|
|"changing thread model does not change the way it works"

Correct. The threading option applies only to MultiUse, not to
SingleUse, so this is identical to SingleUse - Thread/Object.

Clear as mud? :-)
Jul 17 '05 #2
On Mon, 26 Jul 2004 18:45:39 -0700, "Steve Gerrard"
<no************ *@comcast.net> wrote:

"AnalogKid" <AnalogKid17@(m ore_than_warm)m ail.com> wrote in message
news:mq******* *************** **********@4ax. com...
| Short question:
| What's the difference between SingleUse and MultiUse ?
|
| Long question:
| I've been writing some sample code to see how different Instancing
| values and threading models work. I tried all main combinations of
| Instancing (Multiuse/Singleuse) and of Threading models (per
| object/pool). Here's what I found:
|
| MultiUse - Thread per Object
| One new object for each request

Each object is created by the same instance of the activex.exe. If there
is a module in the activex.exe with public data, all of the objects
could see that data, even if they are created by different applications.
Each object has its own thread.

Would you be kind enough to post some sample code to prove this ? I
modified my code to read/write a public property and each object
created has its own copy. When you say public data I assume you meana
public property in the MultiUse class, correct ?
|
| SingleUse - Thread per Object
| One new object for each request
|
Each object is created by a new instance of the activex.exe. Each object
can see public data only in its own instance of the activex.exe. Each
object has its own thread (actually, each has its own process).

Again, I get the same result. No shared data.
| MultiUse - Thread Pool (w/ 1 thread)
| One object reused by all requests
|

Not quite. Actually nearly the same as MultiUse Thread/Object, except
that all the objects will be serviced using the same thread. You can
still create multiple, discreet objects.

| SingleUse - Thread Pool (w/ 1 thread)
| One new object for each request
|
|"changing thread model does not change the way it works"

Correct. The threading option applies only to MultiUse, not to
SingleUse, so this is identical to SingleUse - Thread/Object.

Clear as mud? :-)

Thank you for trying to explain this to me, I beg you not to give
up... I think part of the problem is in terminology. The way I see it
there is 1 ActiveX that contains n Classes. Each class can be
instantiated x times to create x copies of itself (objects).

On top of this you talk about instances of the ActiveX, do you mean
instance of one of the ActiveX Classes ?

Thanks
AK

PS: I haven't even asked questions about Apartment and Single threaded
in DLLs yet... Hopefully that will be easier once EXEs are assimiltaed
:-)
Jul 17 '05 #3

"AnalogKid" <AnalogKid17@(m ore_than_warm)m ail.com> wrote in message
news:9n******** *************** *********@4ax.c om...
| On Mon, 26 Jul 2004 18:45:39 -0700, "Steve Gerrard"
| <no************ *@comcast.net> wrote:
|
| >| MultiUse - Thread per Object
| >
| >Each object is created by the same instance of the activex.exe. If
there
| >is a module in the activex.exe with public data, all of the objects
| >could see that data, even if they are created by different
applications.
| >Each object has its own thread.
| >
|
| Would you be kind enough to post some sample code to prove this ? I
| modified my code to read/write a public property and each object
| created has its own copy. When you say public data I assume you meana
| public property in the MultiUse class, correct ?
|

No, by public data I mean in a bas module. Each object instance will
have its own class data, but they can retrieve a "shared" value from the
bas module.

Add this to your activex.exe, and set its project startup property to
sub main:

Public globalStart As Single

Public Sub Main()
globalStart = Timer
End Sub

Then put a public property in your class, along with what you have, like
this:
Public Property GetStart() As Single
GetStart = globalStart
End Property

In your test code, you should be able to see that each object instance
has its own class data, but they all return the same value for GetStart.
It will help if you delay 1 or two seconds between each object creation,
and don't discard any till the test is over. If you look at the process
list in Task Manager while several objects are still alive, you should
see only one copy of your activex.exe loaded.

| >|
| >| SingleUse - Thread per Object
|
| >Each object is created by a new instance of the activex.exe. Each
object
| >can see public data only in its own instance of the activex.exe. Each
| >object has its own thread (actually, each has its own process).
| >
|
| Again, I get the same result. No shared data.

If you do the same thing with this activex.exe, you should discover that
with SingleUse, each object instance has its own class data, but now
each returns a different value for GetStart. If you look at the process
list in Task Manager while several objects are still alive, you should
see that several copies of your activex.exe are loaded.

| Thank you for trying to explain this to me, I beg you not to give
| up... I think part of the problem is in terminology. The way I see it
| there is 1 ActiveX that contains n Classes. Each class can be
| instantiated x times to create x copies of itself (objects).
|
| On top of this you talk about instances of the ActiveX, do you mean
| instance of one of the ActiveX Classes ?
|

Multiple instance of an activex.exe: in task manager, multiple copies of
the exe are loaded in the process list. This is similar to starting up
several copies of Excel or some other program.

Note that threading has nothing to do with instances of objects, or
instances(copie s) of the activex.exe getting loaded. Threading is just
about how multiple objects created from a multiuse class do their work -
either by sharing one or more threads, or by each having its own thread
assigned.
Jul 17 '05 #4
On Wed, 28 Jul 2004 19:10:31 -0700, "Steve Gerrard"
<no************ *@comcast.net> wrote:

Thanks for your reply, see mine below...

"AnalogKid" <AnalogKid17@(m ore_than_warm)m ail.com> wrote in message
news:9n******* *************** **********@4ax. com...
| On Mon, 26 Jul 2004 18:45:39 -0700, "Steve Gerrard"
| <no************ *@comcast.net> wrote:
|
| >| MultiUse - Thread per Object
| >
| >Each object is created by the same instance of the activex.exe. If there
| >is a module in the activex.exe with public data, all of the objects
| >could see that data, even if they are created by different aapplications.
| >Each object has its own thread.
| >
|
| Would you be kind enough to post some sample code to prove this ? I
| modified my code to read/write a public property and each object
| created has its own copy. When you say public data I assume you meana
| public property in the MultiUse class, correct ?
|

No, by public data I mean in a bas module. Each object instance will
have its own class data, but they can retrieve a "shared" value from the
bas module.

Add this to your activex.exe, and set its project startup property to
sub main:

Public globalStart As Single

Public Sub Main()
globalStart = Timer
End Sub

Then put a public property in your class, along with what you have, like
this:
Public Property GetStart() As Single
GetStart = globalStart
End Property

In your test code, you should be able to see that each object instance
has its own class data, but they all return the same value for GetStart.
It will help if you delay 1 or two seconds between each object creation,
and don't discard any till the test is over. If you look at the process
list in Task Manager while several objects are still alive, you should
see only one copy of your activex.exe loaded.
Steve, I had done a similar test, and while I correctly see one
instance of the MU server and multiple of the SU server in the
processes, I still see one copy of the public data per client, ie each
has its own GetStart value!
| >|
| >| SingleUse - Thread per Object
|
| >Each object is created by a new instance of the activex.exe. Each object
| >can see public data only in its own instance of the activex.exe. Each
| >object has its own thread (actually, each has its own process).
| >
|
| Again, I get the same result. No shared data.

If you do the same thing with this activex.exe, you should discover that
with SingleUse, each object instance has its own class data, but now
each returns a different value for GetStart. If you look at the process
list in Task Manager while several objects are still alive, you should
see that several copies of your activex.exe are loaded.

| Thank you for trying to explain this to me, I beg you not to give
| up... I think part of the problem is in terminology. The way I see it
| there is 1 ActiveX that contains n Classes. Each class can be
| instantiated x times to create x copies of itself (objects).
|
| On top of this you talk about instances of the ActiveX, do you mean
| instance of one of the ActiveX Classes ?
|

Multiple instance of an activex.exe: in task manager, multiple copies of
the exe are loaded in the process list. This is similar to starting up
several copies of Excel or some other program.

Note that threading has nothing to do with instances of objects, or
instances(copi es) of the activex.exe getting loaded. Threading is just
about how multiple objects created from a multiuse class do their work -
either by sharing one or more threads, or by each having its own thread
assigned.

This is also hard to prove with test code: both "Thread per Object"
and "Thread Pool" lock creation of new objects when one is busy.

Thanks again for your help!
Jul 17 '05 #5

"AnalogKid" <AnalogKid17@(m ore_than_warm)m ail.com> wrote in message
news:io******** *************** *********@4ax.c om...
| On Wed, 28 Jul 2004 19:10:31 -0700, "Steve Gerrard"
| <no************ *@comcast.net> wrote:
|
| >
| >Add this to your activex.exe, and set its project startup property to
| >sub main:
| >
| >Public globalStart As Single
| >
| >Public Sub Main()
| > globalStart = Timer
| >End Sub
| >

The above must be in a .bas module, not in a class definition.

| >Then put a public property in your class, along with what you have,
like
| >this:
| >Public Property GetStart() As Single
| > GetStart = globalStart
| >End Property
| >
| >In your test code, you should be able to see that each object
instance
| >has its own class data, but they all return the same value for
GetStart.
| >It will help if you delay 1 or two seconds between each object
creation,
| >and don't discard any till the test is over. If you look at the
process
| >list in Task Manager while several objects are still alive, you
should
| >see only one copy of your activex.exe loaded.
| >
| Steve, I had done a similar test, and while I correctly see one
| instance of the MU server and multiple of the SU server in the
| processes, I still see one copy of the public data per client, ie each
| has its own GetStart value!
|

I know for a fact this works for a MultiUse class, so you must have
something wrong. Was the public data you checked stored in a .bas
module, not a class?
Jul 17 '05 #6
Steve,
Sorry for the interruption (short vacation...) I think I undesrstood
at least part of the problem. See below:

On Thu, 29 Jul 2004 18:42:04 -0700, "Steve Gerrard"
<no************ *@comcast.net> wrote:
| >
| Steve, I had done a similar test, and while I correctly see one
| instance of the MU server and multiple of the SU server in the
| processes, I still see one copy of the public data per client, ie each
| has its own GetStart value!
|
I know for a fact this works for a MultiUse class, so you must have
something wrong. Was the public data you checked stored in a .bas
module, not a class?

The problem is that my Threading Model was set on Thread per Object,
as opposed to the default, Thread Pool 1. Now I can see one copy of
global data for all instantiations.

This means that sharing the same global data is actually a matter of
threads, it's not a prerogative of *all* MultiUse classes, but only
when all clients communicate on the same thread (ie, Thread Pool w/ 1
thread). As soon as you have multiple threads or Threads per Object
(my previous test environment), even global data is duplicated for
each new object created.

Now that we have determined this, my reviewed summary of permutations
looks like this:

MultiUse - Thread per Object
1 process in TaskManager
One new object for each request (each w/ its own data)

SingleUse - Thread per Object
Multiple processes in TaskManager
One new object for each request (each w/ its own data)

MultiUse - Thread Pool (w/ 1 thread)
1 process in TaskManager
One object reused by all requests (global data is in common)

SingleUse - Thread Pool (w/ 1 thread)
Multiple processes in TaskManager
One new object for each request (each w/ its own data)

In conclusion:
a) For SingleUse the Thread Model box should be grayed out, being able
to choose between TpO and TP is just useless confusion. Even with
Thread Pool 1, all created objects work on different threads.
b) MultiUse with a 1 thread pool allows to share global data
c) MultiUse with TpO is like SingleUse, except that there is always
one process for MUs while SUs create one every time a class is
instantiated.

Hopefully the above is correct... can anybody confirm ?

Many thanks to Steve!
AK

Jul 17 '05 #7
comments in line:

"AnalogKid" <AnalogKid17@(m ore_than_warm)m ail.com> wrote in message
news:pn******** *************** *********@4ax.c om...
| Steve,
| Sorry for the interruption (short vacation...) I think I undesrstood
| at least part of the problem. See below:

I'm doing one next week. I believe all vacations turn out to be short.
:)

| Now that we have determined this, my reviewed summary of permutations
| looks like this:

In all of the below, your use of the word object is confusing. An object
is an instance of a class, which is distinct from an instance of the
..exe in task manager. In all of the below, you get a new object for each
request, never the same object.

| MultiUse - Thread per Object
| 1 process in TaskManager
| One new object for each request (each w/ its own data)

I confirm this. It seems a little suprising, but there is no shared
global data in this case, even though there is only one instance of the
..exe loaded.

| SingleUse - Thread per Object
| Multiple processes in TaskManager
| One new object for each request (each w/ its own data)

And no global data in common. Each object comes from a different .exe
instance in task manager.

| MultiUse - Thread Pool (w/ 1 thread)
| 1 process in TaskManager
| One object reused by all requests (global data is in common)

Thats the language I don't like. Each object is still a distinct object,
with its own class data. Only the global data that is not part of a
class is common to them.

| SingleUse - Thread Pool (w/ 1 thread)
| Multiple processes in TaskManager
| One new object for each request (each w/ its own data)

Yup. SingleUse is SingleUse .

| In conclusion:

| a) For SingleUse the Thread Model box should be grayed out, being able
| to choose between TpO and TP is just useless confusion. Even with
| Thread Pool 1, all created objects work on different threads.

Correct. At least it is documented as such. The only reason I can see
for it is that the threading model applies to the whole project, and it
is possible to have both SingleUse and MultiUse classes in the same exe.
Figuring out what happens with that can be your next project. :)

| b) MultiUse with a 1 thread pool allows to share global data

Right.

| c) MultiUse with TpO is like SingleUse, except that there is always
| one process for MUs while SUs create one every time a class is
| instantiated.
|

That seems to be right, odd as it is. Why would you go with SU, if
MU+TPO gets you the same isolation with less loading up of duplicate
exes?
Jul 17 '05 #8
On Wed, 4 Aug 2004 20:05:34 -0700, "Steve Gerrard"
<my********@com cast.net> wrote:
comments in line:

"AnalogKid" <AnalogKid17@(m ore_than_warm)m ail.com> wrote in message
news:pn******* *************** **********@4ax. com...
| Steve,
| Sorry for the interruption (short vacation...) I think I undesrstood
| at least part of the problem. See below:

I'm doing one next week. I believe all vacations turn out to be short.
:)

| Now that we have determined this, my reviewed summary of permutations
| looks like this:

In all of the below, your use of the word object is confusing. An object
is an instance of a class, which is distinct from an instance of the
.exe in task manager. In all of the below, you get a new object for each
request, never the same object.

| MultiUse - Thread per Object
| 1 process in TaskManager
| One new object for each request (each w/ its own data)

I confirm this. It seems a little suprising, but there is no shared
global data in this case, even though there is only one instance of the
.exe loaded.

| SingleUse - Thread per Object
| Multiple processes in TaskManager
| One new object for each request (each w/ its own data)

And no global data in common. Each object comes from a different .exe
instance in task manager.

| MultiUse - Thread Pool (w/ 1 thread)
| 1 process in TaskManager
| One object reused by all requests (global data is in common)

Thats the language I don't like. Each object is still a distinct object,
with its own class data. Only the global data that is not part of a
class is common to them.
Actually my language was correct; my understanding was wrong, though.
I was actually under the impression that all objects created would
point to the same one, but I see now that they are all distinct ones.
| SingleUse - Thread Pool (w/ 1 thread)
| Multiple processes in TaskManager
| One new object for each request (each w/ its own data)

Yup. SingleUse is SingleUse .

| In conclusion:

| a) For SingleUse the Thread Model box should be grayed out, being able
| to choose between TpO and TP is just useless confusion. Even with
| Thread Pool 1, all created objects work on different threads.

Correct. At least it is documented as such. The only reason I can see
for it is that the threading model applies to the whole project, and it
is possible to have both SingleUse and MultiUse classes in the same exe.
Figuring out what happens with that can be your next project. :)

| b) MultiUse with a 1 thread pool allows to share global data

Right.

| c) MultiUse with TpO is like SingleUse, except that there is always
| one process for MUs while SUs create one every time a class is
| instantiated.
|

That seems to be right, odd as it is. Why would you go with SU, if
MU+TPO gets you the same isolation with less loading up of duplicate
exes?


Jul 17 '05 #9

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

Similar topics

1
3384
by: Marwan | last post by:
Hello I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking. If i put the thread to sleep in my delegate call, the application is well behaved (no UI freeze), but the call to the com object causes the UI to lock up Do I have to manage calls...
18
8396
by: DartmanX | last post by:
Is there a simple way to determine if someone using Internet Explorer has completely disabled ActiveX controls? Jason
5
5366
by: Adam Clauss | last post by:
I am creating a plugin for MS Outlook. Upon clicking a toolbar button, I create series of threads (variable number each time). Within each thread, I start a form using Application.Run(...). This form contains the Web Browser ActiveX control. Upon creating the form, I get a ThreadStateException "Could not instantiate ActiveX control ........
7
4383
by: Jarod_24 | last post by:
I just downloaded a activex control that was written in C# and tried to view it on my PDA's Internet Explorer. At my regular PC it displayed just fine, but nothing showed up on the pda. Do ActiveX controls that are to be used by a pda need to be written in the ..net compact framework, or am i missing something else here? i have a HP iPaq...
5
5691
by: Yeti | last post by:
Hey everyone, I am modifying code upgraded from VB 6 to 2005. I need to run the 2005 code in the MTA mode so I set a sub main procedure in my module which runs first when the program starts: Public theApplicationForm As New Form1 <MTAThread()> Public Sub main() Application.Run(theApplicationForm) End Sub
1
3076
by: Janiek Buysrogge | last post by:
Hello, I've written a Windows Forms application in .NET 2.0 and am exposing it to COM using the checkbox in Project Properties and by adding some register functions and adding it to the GAC. I'm using the ActiveX Test Container (tstcon32.exe) and I'm able to add the control to the container. All this works, well almost... I'm using some...
6
8032
by: hufaunder | last post by:
I have an ActiveX component that I want to use in a library that I am writing. As a first test I used the ActiveX component in a windows form application. Adding the component created: Ax.dll .dll I can not call the functions in the ActiveX component. In the next step I tried to use the ActiveX component in a class library. I simply...
2
2820
by: =?Utf-8?B?Sm9obiBG?= | last post by:
Hello All, I have a question about using an ActiveX control with a Windows Servce in C#. I believe it is not possible to properly setup an ActiveX control in a windows service as the particular ActiveX control we're using (GrFinger for fingerprint reader)implements several event handlers. It is also my understanding that there is no...
1
1928
by: Jialiang Ge [MSFT] | last post by:
Hello Philippe, In addition to bruce's points, I'd suggest the KB article http://support.microsoft.com/kb/317392. It demonstrates how to host an ActiveX control in ASP.NET (for your first question), and points out that ActiveX control is a pure client-side control, the server-side code cannot access this control (for your second question)....
0
7707
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...
0
8086
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...
0
6432
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...
1
5605
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...
0
5296
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...
0
3743
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2227
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
1
1325
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1048
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...

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.