I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up:
1.. A classic ASP page instantiates and calls MethodA on COM+ Class (C1).
2.. MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class (N1). (Note: N1 has been registered using RegASM and is present in the GAC).
3.. MethodB of .NET class (N1) uses the ThreadPool.Queu eUserWorkItem method to queue up a call to MethodC on .NET Class (N2).
4.. MethodC of .NET Class (N2), (called on a ThreadPool thread), instantiates and calls MethodD on COM+ class (C2).
5.. MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class (C3).
6.. Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2) to retrieve the results of the "background " processing. These results are passed back to COM+ Class (C1) and ultimately displayed on the ASP page.
Note: All COM+ classes are registered within the same COM+ application; and this application is configured as a "Library" application.
I believe this sequence of calls results in the following transitions:
1.. An IIS worker thread, (running C1), transitions to .NET managed thread, (running N1). I'm not at all clear as to what process owns the ..NET thread.
2.. As a result of item#1 a .NET ThreadPool thread, (running N2), transitions to a COM+ thread, (running C2).
3.. I'm assuming the same COM+ Thread from item#2 is used to run C3.
4.. The COM+ Thread running C2 and C3 completes and transitions back to the .NET ThreadPool thread running N2.
5.. Based on a flag exposed as a static member of N2, the "original" ..NET Thread begins accessing static members of N2. (These static members are used to aggregate results across multiple ThreadPool threads.)
6.. Finally, the "original" .NET thread transitions back to the IIS worker thread running C1.
After modifying Machine.Config such that the "ProcessMod el" tag used the "system" account instead of the "machine" account, I was able to get this working in Debug mode. The modification was required to enable transition #2 (listed above). Prior to making this modification an exception was thrown indicating an inability to call COM+ class C2. (Sorry, I don't recall the exact exception.)
When I say Debug mode, I'm referring to running the code within the VS.NET and VS6 IDEs and stepping between break points.
With everything working in Debug mode, I then attempted to execute the code without debugging. Based on well placed App.LogEvent and EventLog.WriteE ntry calls, it appears that the following is occurring:
1.. All calls prior to the calling of COM+ Class C3 appear to be working.
2.. The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant returned from this call is empty. During successful execution the resulting variant contains an array with a "UBound" of 5. The real puzzling thing about this situation is that an error with COM+ class C3 should result in a variant containing an array with a "UBound" of 3. There should always be an array returned from COM+ C3!
So the questions are as follows:
1.. Is it possible that the return values, (which are passed ByRef), aren't being marshalled properly between COM+ Class C2 and COM+ Class C3?
2.. Is it possible that the call from COM+ Class C2 to COM+ Class C3 is failing silently? (Placing App.LogEvent calls within COM+ Class C3 requires the involvement of another team.)
3.. Is there some security or thread related issue here that I'm just not seeing? And does this underlying issue explain why things work during Debug and fail when not running under an IDE managed thread?
Thanks for taking the time to read all of that. :-) 5 2759
Duane,
I believe that there is a threading issue here that could be
contributing to some of the issues you are seeing. The threads in the
ThreadPool class do not belong to any COM compartment by default. This is a
big issue, because components that derive from ServicedCompone nt are not
free-threaded. From the section of the .NET framework documentation titled
"Managed and Unmanaged Threading in Microsoft Windows":
Managed objects that are exposed to COM behave as if they had aggregated the
free-threaded marshaler. In other words, they can be called from any COM
apartment in a free-threaded manner. The only managed objects that do not
exhibit this free-threaded behavior are those objects that derive from
ServicedCompone nt.
Since you declared that your components are COM+ components, I'm
assuming they are all derived from ServicedCompone nt.
Because the apartment is not set up correctly, you probably are not
getting the correct context for your components, which can result in a
number of the issues that you are seeing.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- casper(1 spelled out){at)caspers (where I live, rhymes with
mouse)<dot]com
"Duane Pressley" <Du****@AdminSe rver.com> wrote in message
news:ea******** ********@tk2msf tngp13.phx.gbl. ..
I'm looking for someone to help me make sense of the results I'm observing
when using the ThreadPool class in a COM-Interop scenario. Here's the set
up:
A classic ASP page instantiates and calls MethodA on COM+ Class (C1).
MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class
(N1). (Note: N1 has been registered using RegASM and is present in the GAC).
MethodB of .NET class (N1) uses the ThreadPool.Queu eUserWorkItem method to
queue up a call to MethodC on .NET Class (N2).
MethodC of .NET Class (N2), (called on a ThreadPool thread), instantiates
and calls MethodD on COM+ class (C2).
MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class
(C3).
Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2)
to retrieve the results of the "background " processing. These results are
passed back to COM+ Class (C1) and ultimately displayed on the ASP page.
Note: All COM+ classes are registered within the same COM+ application;
and this application is configured as a "Library" application.
I believe this sequence of calls results in the following transitions:
An IIS worker thread, (running C1), transitions to .NET managed thread,
(running N1). I'm not at all clear as to what process owns the .NET thread.
As a result of item#1 a .NET ThreadPool thread, (running N2), transitions to
a COM+ thread, (running C2).
I'm assuming the same COM+ Thread from item#2 is used to run C3.
The COM+ Thread running C2 and C3 completes and transitions back to the .NET
ThreadPool thread running N2.
Based on a flag exposed as a static member of N2, the "original" .NET Thread
begins accessing static members of N2. (These static members are used to
aggregate results across multiple ThreadPool threads.)
Finally, the "original" .NET thread transitions back to the IIS worker
thread running C1.
After modifying Machine.Config such that the "ProcessMod el" tag used the
"system" account instead of the "machine" account, I was able to get this
working in Debug mode. The modification was required to enable transition #2
(listed above). Prior to making this modification an exception was thrown
indicating an inability to call COM+ class C2. (Sorry, I don't recall the
exact exception.)
When I say Debug mode, I'm referring to running the code within the
VS.NET and VS6 IDEs and stepping between break points.
With everything working in Debug mode, I then attempted to execute the code
without debugging. Based on well placed App.LogEvent and EventLog.WriteE ntry
calls, it appears that the following is occurring:
All calls prior to the calling of COM+ Class C3 appear to be working.
The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant
returned from this call is empty. During successful execution the resulting
variant contains an array with a "UBound" of 5. The real puzzling thing
about this situation is that an error with COM+ class C3 should result in a
variant containing an array with a "UBound" of 3. There should always be an
array returned from COM+ C3!
So the questions are as follows:
Is it possible that the return values, (which are passed ByRef), aren't
being marshalled properly between COM+ Class C2 and COM+ Class C3?
Is it possible that the call from COM+ Class C2 to COM+ Class C3 is failing
silently? (Placing App.LogEvent calls within COM+ Class C3 requires the
involvement of another team.)
Is there some security or thread related issue here that I'm just not
seeing? And does this underlying issue explain why things work during Debug
and fail when not running under an IDE managed thread?
Thanks for taking the time to read all of that. :-)
Thanks for the reply Nicholas.
To clarify things a bit:
1.. There are 2 .NET classes in my scenario, and neither of these are derived from ServicedCompone nt.
2.. The COM+ classes involved, (C1, C2, and C3), are all members of the same COM+ application.
Are you suggesting that I should move one of my .NET classes into COM+?
In an attempt to explore your thoughts that this may be related to the COM apartment of the ThreadPool thread, I did the following:
1.. Marked the N2 method, (this is the method run on the ThreadPool thread), with the [STAThread] attribute. This produced the same results.
2.. Used the Thread.CurrentT hread.Apartment State property to set the ApartmentState to STA. Again same results as before.
Thanks for the post...any other ideas?
"Nicholas Paldino [.NET/C# MVP]" <casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com> wrote in message news:u0******** ******@TK2MSFTN GP11.phx.gbl... Duane, I believe that there is a threading issue here that could be contributing to some of the issues you are seeing. The threads in the ThreadPool class do not belong to any COM compartment by default. This is a big issue, because components that derive from ServicedCompone nt are not free-threaded. From the section of the .NET framework documentation titled "Managed and Unmanaged Threading in Microsoft Windows": Managed objects that are exposed to COM behave as if they had aggregated the free-threaded marshaler. In other words, they can be called from any COM apartment in a free-threaded manner. The only managed objects that do not exhibit this free-threaded behavior are those objects that derive from ServicedCompone nt. Since you declared that your components are COM+ components, I'm assuming they are all derived from ServicedCompone nt. Because the apartment is not set up correctly, you probably are not getting the correct context for your components, which can result in a number of the issues that you are seeing. Hope this helps. -- - Nicholas Paldino [.NET/C# MVP] - casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com "Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:ea******** ********@tk2msf tngp13.phx.gbl. .. I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: A classic ASP page instantiates and calls MethodA on COM+ Class (C1). MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class (N1). (Note: N1 has been registered using RegASM and is present in the GAC). MethodB of .NET class (N1) uses the ThreadPool.Queu eUserWorkItem method to queue up a call to MethodC on .NET Class (N2). MethodC of .NET Class (N2), (called on a ThreadPool thread), instantiates and calls MethodD on COM+ class (C2). MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class (C3). Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2) to retrieve the results of the "background " processing. These results are passed back to COM+ Class (C1) and ultimately displayed on the ASP page. Note: All COM+ classes are registered within the same COM+ application; and this application is configured as a "Library" application. I believe this sequence of calls results in the following transitions: An IIS worker thread, (running C1), transitions to .NET managed thread, (running N1). I'm not at all clear as to what process owns the .NET thread. As a result of item#1 a .NET ThreadPool thread, (running N2), transitions to a COM+ thread, (running C2). I'm assuming the same COM+ Thread from item#2 is used to run C3. The COM+ Thread running C2 and C3 completes and transitions back to the .NET ThreadPool thread running N2. Based on a flag exposed as a static member of N2, the "original" .NET Thread begins accessing static members of N2. (These static members are used to aggregate results across multiple ThreadPool threads.) Finally, the "original" .NET thread transitions back to the IIS worker thread running C1. After modifying Machine.Config such that the "ProcessMod el" tag used the "system" account instead of the "machine" account, I was able to get this working in Debug mode. The modification was required to enable transition #2 (listed above). Prior to making this modification an exception was thrown indicating an inability to call COM+ class C2. (Sorry, I don't recall the exact exception.) When I say Debug mode, I'm referring to running the code within the VS.NET and VS6 IDEs and stepping between break points. With everything working in Debug mode, I then attempted to execute the code without debugging. Based on well placed App.LogEvent and EventLog.WriteE ntry calls, it appears that the following is occurring: All calls prior to the calling of COM+ Class C3 appear to be working. The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant returned from this call is empty. During successful execution the resulting variant contains an array with a "UBound" of 5. The real puzzling thing about this situation is that an error with COM+ class C3 should result in a variant containing an array with a "UBound" of 3. There should always be an array returned from COM+ C3! So the questions are as follows: Is it possible that the return values, (which are passed ByRef), aren't being marshalled properly between COM+ Class C2 and COM+ Class C3? Is it possible that the call from COM+ Class C2 to COM+ Class C3 is failing silently? (Placing App.LogEvent calls within COM+ Class C3 requires the involvement of another team.) Is there some security or thread related issue here that I'm just not seeing? And does this underlying issue explain why things work during Debug and fail when not running under an IDE managed thread? Thanks for taking the time to read all of that. :-)
After further review, it appears that my problem was due to an apparent inability to call an in-process STA COM+ Class from a MTA "ThreadPool " thread.
Moving COM+ Class (C2) to an out-of-process "Server" application allowed me to "work-around" my initial issue.
Does anyone know if it is possible to successfully call an in-process STA COM+ Class from a "ThreadPool " thread?
"Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:eG******** *****@TK2MSFTNG P12.phx.gbl...
Thanks for the reply Nicholas.
To clarify things a bit:
1.. There are 2 .NET classes in my scenario, and neither of these are derived from ServicedCompone nt.
2.. The COM+ classes involved, (C1, C2, and C3), are all members of the same COM+ application.
Are you suggesting that I should move one of my .NET classes into COM+?
In an attempt to explore your thoughts that this may be related to the COM apartment of the ThreadPool thread, I did the following:
1.. Marked the N2 method, (this is the method run on the ThreadPool thread), with the [STAThread] attribute. This produced the same results.
2.. Used the Thread.CurrentT hread.Apartment State property to set the ApartmentState to STA. Again same results as before.
Thanks for the post...any other ideas?
"Nicholas Paldino [.NET/C# MVP]" <casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com> wrote in message news:u0******** ******@TK2MSFTN GP11.phx.gbl... Duane, I believe that there is a threading issue here that could be contributing to some of the issues you are seeing. The threads in the ThreadPool class do not belong to any COM compartment by default. This is a big issue, because components that derive from ServicedCompone nt are not free-threaded. From the section of the .NET framework documentation titled "Managed and Unmanaged Threading in Microsoft Windows": Managed objects that are exposed to COM behave as if they had aggregated the free-threaded marshaler. In other words, they can be called from any COM apartment in a free-threaded manner. The only managed objects that do not exhibit this free-threaded behavior are those objects that derive from ServicedCompone nt. Since you declared that your components are COM+ components, I'm assuming they are all derived from ServicedCompone nt. Because the apartment is not set up correctly, you probably are not getting the correct context for your components, which can result in a number of the issues that you are seeing. Hope this helps. -- - Nicholas Paldino [.NET/C# MVP] - casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com "Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:ea******** ********@tk2msf tngp13.phx.gbl. .. I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: A classic ASP page instantiates and calls MethodA on COM+ Class (C1). MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class (N1). (Note: N1 has been registered using RegASM and is present in the GAC). MethodB of .NET class (N1) uses the ThreadPool.Queu eUserWorkItem method to queue up a call to MethodC on .NET Class (N2). MethodC of .NET Class (N2), (called on a ThreadPool thread), instantiates and calls MethodD on COM+ class (C2). MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class (C3). Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2) to retrieve the results of the "background " processing. These results are passed back to COM+ Class (C1) and ultimately displayed on the ASP page. Note: All COM+ classes are registered within the same COM+ application; and this application is configured as a "Library" application. I believe this sequence of calls results in the following transitions: An IIS worker thread, (running C1), transitions to .NET managed thread, (running N1). I'm not at all clear as to what process owns the .NET thread. As a result of item#1 a .NET ThreadPool thread, (running N2), transitions to a COM+ thread, (running C2). I'm assuming the same COM+ Thread from item#2 is used to run C3. The COM+ Thread running C2 and C3 completes and transitions back to the .NET ThreadPool thread running N2. Based on a flag exposed as a static member of N2, the "original" ..NET Thread begins accessing static members of N2. (These static members are used to aggregate results across multiple ThreadPool threads.) Finally, the "original" .NET thread transitions back to the IIS worker thread running C1. After modifying Machine.Config such that the "ProcessMod el" tag used the "system" account instead of the "machine" account, I was able to get this working in Debug mode. The modification was required to enable transition #2 (listed above). Prior to making this modification an exception was thrown indicating an inability to call COM+ class C2. (Sorry, I don't recall the exact exception.) When I say Debug mode, I'm referring to running the code within the VS.NET and VS6 IDEs and stepping between break points. With everything working in Debug mode, I then attempted to execute the code without debugging. Based on well placed App.LogEvent and EventLog.WriteE ntry calls, it appears that the following is occurring: All calls prior to the calling of COM+ Class C3 appear to be working. The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant returned from this call is empty. During successful execution the resulting variant contains an array with a "UBound" of 5. The real puzzling thing about this situation is that an error with COM+ class C3 should result in a variant containing an array with a "UBound" of 3. There should always be an array returned from COM+ C3! So the questions are as follows: Is it possible that the return values, (which are passed ByRef), aren't being marshalled properly between COM+ Class C2 and COM+ Class C3? Is it possible that the call from COM+ Class C2 to COM+ Class C3 is failing silently? (Placing App.LogEvent calls within COM+ Class C3 requires the involvement of another team.) Is there some security or thread related issue here that I'm just not seeing? And does this underlying issue explain why things work during Debug and fail when not running under an IDE managed thread? Thanks for taking the time to read all of that. :-)
If i use the threadpool for like 3.. to 5 threads , is there a gurantee that they will be started pretty close to when i requested them? or what would make them wait somehow, is there a way to determine that after a period of time that a thread pooled hasnt started then i can abort it and do a new thread start?
"Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:Os******** ******@TK2MSFTN GP10.phx.gbl...
After further review, it appears that my problem was due to an apparent inability to call an in-process STA COM+ Class from a MTA "ThreadPool " thread.
Moving COM+ Class (C2) to an out-of-process "Server" application allowed me to "work-around" my initial issue.
Does anyone know if it is possible to successfully call an in-process STA COM+ Class from a "ThreadPool " thread?
"Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:eG******** *****@TK2MSFTNG P12.phx.gbl...
Thanks for the reply Nicholas.
To clarify things a bit:
1.. There are 2 .NET classes in my scenario, and neither of these are derived from ServicedCompone nt.
2.. The COM+ classes involved, (C1, C2, and C3), are all members of the same COM+ application.
Are you suggesting that I should move one of my .NET classes into COM+?
In an attempt to explore your thoughts that this may be related to the COM apartment of the ThreadPool thread, I did the following:
1.. Marked the N2 method, (this is the method run on the ThreadPool thread), with the [STAThread] attribute. This produced the same results.
2.. Used the Thread.CurrentT hread.Apartment State property to set the ApartmentState to STA. Again same results as before.
Thanks for the post...any other ideas?
"Nicholas Paldino [.NET/C# MVP]" <casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com> wrote in message news:u0******** ******@TK2MSFTN GP11.phx.gbl... Duane, I believe that there is a threading issue here that could be contributing to some of the issues you are seeing. The threads in the ThreadPool class do not belong to any COM compartment by default. This is a big issue, because components that derive from ServicedCompone nt are not free-threaded. From the section of the .NET framework documentation titled "Managed and Unmanaged Threading in Microsoft Windows": Managed objects that are exposed to COM behave as if they had aggregated the free-threaded marshaler. In other words, they can be called from any COM apartment in a free-threaded manner. The only managed objects that do not exhibit this free-threaded behavior are those objects that derive from ServicedCompone nt. Since you declared that your components are COM+ components, I'm assuming they are all derived from ServicedCompone nt. Because the apartment is not set up correctly, you probably are not getting the correct context for your components, which can result in a number of the issues that you are seeing. Hope this helps. -- - Nicholas Paldino [.NET/C# MVP] - casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com "Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:ea******** ********@tk2msf tngp13.phx.gbl. .. I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: A classic ASP page instantiates and calls MethodA on COM+ Class (C1). MethodA of COM+ class (C1) instantiates and calls MethodB of .NET class (N1). (Note: N1 has been registered using RegASM and is present in the GAC). MethodB of .NET class (N1) uses the ThreadPool.Queu eUserWorkItem method to queue up a call to MethodC on .NET Class (N2). MethodC of .NET Class (N2), (called on a ThreadPool thread), instantiates and calls MethodD on COM+ class (C2). MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class (C3). Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2) to retrieve the results of the "background " processing. These results are passed back to COM+ Class (C1) and ultimately displayed on the ASP page. Note: All COM+ classes are registered within the same COM+ application; and this application is configured as a "Library" application. I believe this sequence of calls results in the following transitions: An IIS worker thread, (running C1), transitions to .NET managed thread, (running N1). I'm not at all clear as to what process owns the ..NET thread. As a result of item#1 a .NET ThreadPool thread, (running N2), transitions to a COM+ thread, (running C2). I'm assuming the same COM+ Thread from item#2 is used to run C3. The COM+ Thread running C2 and C3 completes and transitions back to the .NET ThreadPool thread running N2. Based on a flag exposed as a static member of N2, the "original" ..NET Thread begins accessing static members of N2. (These static members are used to aggregate results across multiple ThreadPool threads.) Finally, the "original" .NET thread transitions back to the IIS worker thread running C1. After modifying Machine.Config such that the "ProcessMod el" tag used the "system" account instead of the "machine" account, I was able to get this working in Debug mode. The modification was required to enable transition #2 (listed above). Prior to making this modification an exception was thrown indicating an inability to call COM+ class C2. (Sorry, I don't recall the exact exception.) When I say Debug mode, I'm referring to running the code within the VS.NET and VS6 IDEs and stepping between break points. With everything working in Debug mode, I then attempted to execute the code without debugging. Based on well placed App.LogEvent and EventLog.WriteE ntry calls, it appears that the following is occurring: All calls prior to the calling of COM+ Class C3 appear to be working. The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant returned from this call is empty. During successful execution the resulting variant contains an array with a "UBound" of 5. The real puzzling thing about this situation is that an error with COM+ class C3 should result in a variant containing an array with a "UBound" of 3. There should always be an array returned from COM+ C3! So the questions are as follows: Is it possible that the return values, (which are passed ByRef), aren't being marshalled properly between COM+ Class C2 and COM+ Class C3? Is it possible that the call from COM+ Class C2 to COM+ Class C3 is failing silently? (Placing App.LogEvent calls within COM+ Class C3 requires the involvement of another team.) Is there some security or thread related issue here that I'm just not seeing? And does this underlying issue explain why things work during Debug and fail when not running under an IDE managed thread? Thanks for taking the time to read all of that. :-)
My experiences so far suggest that you are unable to "predict" when the ThreadPool threads will be started. The the ThreadPool process appears to start the "background " threads based on CPU availability.
Keep in mind, there is no way to "cancel" a "work item" that has been queued using the ThreadPool.Queu eUserWorkItem method. You may need to manage your own pool of threads which would allow to have complete control over the starting, stopping, and aborting of those threads.
Hope that helps.
"Mr.Tickle" <Mr******@mrmen .com> wrote in message news:uQ******** ******@TK2MSFTN GP10.phx.gbl...
If i use the threadpool for like 3.. to 5 threads , is there a gurantee that they will be started pretty close to when i requested them? or what would make them wait somehow, is there a way to determine that after a period of time that a thread pooled hasnt started then i can abort it and do a new thread start?
"Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:Os******** ******@TK2MSFTN GP10.phx.gbl...
After further review, it appears that my problem was due to an apparent inability to call an in-process STA COM+ Class from a MTA "ThreadPool " thread.
Moving COM+ Class (C2) to an out-of-process "Server" application allowed me to "work-around" my initial issue.
Does anyone know if it is possible to successfully call an in-process STA COM+ Class from a "ThreadPool " thread?
"Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:eG******** *****@TK2MSFTNG P12.phx.gbl...
Thanks for the reply Nicholas.
To clarify things a bit:
1.. There are 2 .NET classes in my scenario, and neither of these are derived from ServicedCompone nt.
2.. The COM+ classes involved, (C1, C2, and C3), are all members of the same COM+ application.
Are you suggesting that I should move one of my .NET classes into COM+?
In an attempt to explore your thoughts that this may be related to the COM apartment of the ThreadPool thread, I did the following:
1.. Marked the N2 method, (this is the method run on the ThreadPool thread), with the [STAThread] attribute. This produced the same results.
2.. Used the Thread.CurrentT hread.Apartment State property to set the ApartmentState to STA. Again same results as before.
Thanks for the post...any other ideas?
"Nicholas Paldino [.NET/C# MVP]" <casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com> wrote in message news:u0******** ******@TK2MSFTN GP11.phx.gbl... Duane, I believe that there is a threading issue here that could be contributing to some of the issues you are seeing. The threads in the ThreadPool class do not belong to any COM compartment by default. This is a big issue, because components that derive from ServicedCompone nt are not free-threaded. From the section of the .NET framework documentation titled "Managed and Unmanaged Threading in Microsoft Windows": Managed objects that are exposed to COM behave as if they had aggregated the free-threaded marshaler. In other words, they can be called from any COM apartment in a free-threaded manner. The only managed objects that do not exhibit this free-threaded behavior are those objects that derive from ServicedCompone nt. Since you declared that your components are COM+ components, I'm assuming they are all derived from ServicedCompone nt. Because the apartment is not set up correctly, you probably are not getting the correct context for your components, which can result in a number of the issues that you are seeing. Hope this helps. -- - Nicholas Paldino [.NET/C# MVP] - casper(1 spelled out){at)caspers (where I live, rhymes with mouse)<dot]com "Duane Pressley" <Du****@AdminSe rver.com> wrote in message news:ea******** ********@tk2msf tngp13.phx.gbl. .. I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: A classic ASP page instantiates and calls MethodA on COM+ Class (C1). MethodA of COM+ class (C1) instantiates and calls MethodB of ..NET class (N1). (Note: N1 has been registered using RegASM and is present in the GAC). MethodB of .NET class (N1) uses the ThreadPool.Queu eUserWorkItem method to queue up a call to MethodC on .NET Class (N2). MethodC of .NET Class (N2), (called on a ThreadPool thread), instantiates and calls MethodD on COM+ class (C2). MethodD of COM+ Class (C2) instantiates and calls MethodE on COM+ class (C3). Finally, methodB of .NET Class (N1) uses static members of .NET Class (N2) to retrieve the results of the "background " processing. These results are passed back to COM+ Class (C1) and ultimately displayed on the ASP page. Note: All COM+ classes are registered within the same COM+ application; and this application is configured as a "Library" application. I believe this sequence of calls results in the following transitions: An IIS worker thread, (running C1), transitions to .NET managed thread, (running N1). I'm not at all clear as to what process owns the ..NET thread. As a result of item#1 a .NET ThreadPool thread, (running N2), transitions to a COM+ thread, (running C2). I'm assuming the same COM+ Thread from item#2 is used to run C3. The COM+ Thread running C2 and C3 completes and transitions back to the .NET ThreadPool thread running N2. Based on a flag exposed as a static member of N2, the "original" ..NET Thread begins accessing static members of N2. (These static members are used to aggregate results across multiple ThreadPool threads.) Finally, the "original" .NET thread transitions back to the IIS worker thread running C1. After modifying Machine.Config such that the "ProcessMod el" tag used the "system" account instead of the "machine" account, I was able to get this working in Debug mode. The modification was required to enable transition #2 (listed above). Prior to making this modification an exception was thrown indicating an inability to call COM+ class C2. (Sorry, I don't recall the exact exception.) When I say Debug mode, I'm referring to running the code within the VS.NET and VS6 IDEs and stepping between break points. With everything working in Debug mode, I then attempted to execute the code without debugging. Based on well placed App.LogEvent and EventLog.WriteE ntry calls, it appears that the following is occurring: All calls prior to the calling of COM+ Class C3 appear to be working. The Call to COM+ Class C3 doesn't raise a COM+ error, but the variant returned from this call is empty. During successful execution the resulting variant contains an array with a "UBound" of 5. The real puzzling thing about this situation is that an error with COM+ class C3 should result in a variant containing an array with a "UBound" of 3. There should always be an array returned from COM+ C3! So the questions are as follows: Is it possible that the return values, (which are passed ByRef), aren't being marshalled properly between COM+ Class C2 and COM+ Class C3? Is it possible that the call from COM+ Class C2 to COM+ Class C3 is failing silently? (Placing App.LogEvent calls within COM+ Class C3 requires the involvement of another team.) Is there some security or thread related issue here that I'm just not seeing? And does this underlying issue explain why things work during Debug and fail when not running under an IDE managed thread? Thanks for taking the time to read all of that. :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dan Battagin |
last post by:
Is there a known bug with the interaction between the HttpWebRequest and the
ThreadPool? I current spawn several HttpWebRequest's using
BeginGetResponse, and they work for a while, using worker threads from the
ThreadPool. However, eventually (relatively quickly) there become fewer and
fewer available worker threads in the pool, until there are 0 and a
System.InvalidOperationException occurs with the message: "There were not
enough free...
|
by: memememe |
last post by:
We are queueing stuff on the thread pool and what we are queueing gets done
pretty quick (the method returns fine) but yet its only allowed to run
around 25 times, is there anything I need to do to tell the threadpool that
my method is done running and the thread is to be disposed of?
|
by: Max Adams |
last post by:
Threads and ThreadPool's
If I use a ThreadPool how can I tell when a thead in the threadpool has
exited? I don't want to set a global member variable I would much rather be
able to act on an event
Also (failing this ThreadPool issue) is it possible to create an array of
Worker Threads, can anyone illustrate with code please
Thanks
|
by: doudou-shen |
last post by:
I will use threadpool do some work with threadpool . but I haven't any
information about it . who can help me! thank a lot
|
by: orekin |
last post by:
Hi There
I have been programming C# for a couple of months and am trying to
master Threading.
I understand that ThreadPool uses background threads (see code example
in MSDN page titled 'ThreadPool Class ') .... however I would like
to ensure that all my ThreadPool threads have completed before I exit
my Main function.
| |
by: Sam |
last post by:
Hi All,
I'm trying to write a simple multi-threaded windows service application
using ThreadPool and I'm running into the same problem as described by MS
article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;815637#appliesto .
The sample code down here is from the above article. Would anyone give me
some directions how to overcome the deadlock issue with thread pull. The
exception that I get after all threads in the...
|
by: Kevin |
last post by:
Using this:
http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx
as an example I have a question concerning the reuse of objects. In
the example 10 instances of the Fibonacci class are made and then all
put in the threadpool at once, which is well within the limits of the
threadpool.
However, what happens if you want to do 10,000 Fibonacci calculations
|
by: =?Utf-8?B?RkxEYXZlTQ==?= |
last post by:
I'm developing an application that gets data from 100 sources (via telnet
connections, but you can think stock quotes from a webservice if you like).
I was planning on using the thread pool (25 at a time). I know I would start
all 100 at once and as threads finish, a new thread would become available
and the next one would start.
However, I need to do this over and over (using an app that will run for
days or longer). How can I tell...
|
by: UltimateBanoffee |
last post by:
Hi,
I'm using asp.net 2.0 and I have an understanding issue here!
I don't quite understand when the available threads in the ThreadPool
are ever used. The application I have running doesn't use
ThreadPool.QueueWorkItem, and doesn't create any other Threads. So say
I have 100 users access my application at the exact same time and they
all call on an aspx that takes a couple of seconds to process. I
gather 100 sessions are active, but...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
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
| |
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...
| |