Threading problem with Managed Extensions

  • Thread starter Thread starter Ken
  • Start date Start date
K

Ken

I have a Windows Form developed in C# using the Microsoft
Web Browser control, which is an old-style COM control.
When I run the form from a .NET application that has an
[STAThread] attribute on the startup object, it works
fine. However, when I run the same form from a C++
application using Managed Extensions for C++, I
get "Server Busy" messages when the message loop blocks. I
believe I need to indicate somehow to the Managed
Extensions that I want to run the code in an STA. How do I
do that?
 
UPDATE: This does not appear to be a threading problem. I
checked the threading model and in both cases it is STA.

So, there is some other difference. "Server busy" messages
do not appear while running the form from a .NET
applicatiob, but they do appear if the form is run through
an MFC application.
 
Hi Ken,
To my understanding, you are using an .NET Application in a MFC Application.
Because there is no direct way to use an .NET Application in MFC app, so I
guess you are using some COM interop mechanism, Then I'd like to know the
context flag in your CoCreateInstance statement. Is it CLSCTX_LOCAL_SERVER?
If yes, mostly the reason of the "Server Busy" problem is because the
thread of your COM Server has been blocked or unable to response for a long
time.
In STA, COM uses the message loop to get and dispatch incoming calls,
normally you should avoid blocking the the message loop, If you really need
do a time-consuming job, you may take a look at this article in KB,
<HOWTO: Prevent Server Busy Dialog Box From appearing During a Length COM
Operation>
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q248019

If you still have problem on this issue, please let me know and I'd
appreciated if you could send me a sample to repro thi problem.
Thanks for using MSDN Newsgroup!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| Content-Class: urn:content-classes:message
| From: "Ken" <[email protected]>
| Sender: "Ken" <[email protected]>
| Subject: Threading problem with Managed Extensions
| Date: Mon, 13 Oct 2003 09:14:59 -0700
| Lines: 10
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcORpSYVXmtEPFysQ9CAztCKDGGjzA==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54331
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a Windows Form developed in C# using the Microsoft
| Web Browser control, which is an old-style COM control.
| When I run the form from a .NET application that has an
| [STAThread] attribute on the startup object, it works
| fine. However, when I run the same form from a C++
| application using Managed Extensions for C++, I
| get "Server Busy" messages when the message loop blocks. I
| believe I need to indicate somehow to the Managed
| Extensions that I want to run the code in an STA. How do I
| do that?
|
 
Thanks for your response.

The article you suggested eventually led us to the
solution, but things did not work exactly as described.
The call AfxOleGetMessageFilter()->EnableBusyDialog
(FALSE); did not disable the busy dialog as documented.
However, when we lengthened the timeout to a really big
number, the dialog stopped occuring.

Consider our issue resolved, but you might want to
investigate if the AfxOleGetMessageFilter()-
EnableBusyDialog(FALSE); is working as described.
-----Original Message-----
Hi Ken,
To my understanding, you are using an .NET Application in a MFC Application.
Because there is no direct way to use an .NET Application in MFC app, so I
guess you are using some COM interop mechanism, Then I'd like to know the
context flag in your CoCreateInstance statement. Is it CLSCTX_LOCAL_SERVER?
If yes, mostly the reason of the "Server Busy" problem is because the
thread of your COM Server has been blocked or unable to response for a long
time.
In STA, COM uses the message loop to get and dispatch incoming calls,
normally you should avoid blocking the the message loop, If you really need
do a time-consuming job, you may take a look at this article in KB,
<HOWTO: Prevent Server Busy Dialog Box From appearing During a Length COM
Operation>
http://support.microsoft.com/default.aspx?scid=kb;en- us;Q248019

If you still have problem on this issue, please let me know and I'd
appreciated if you could send me a sample to repro thi problem.
Thanks for using MSDN Newsgroup!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| Content-Class: urn:content-classes:message
| From: "Ken" <[email protected]>
| Sender: "Ken" <[email protected]>
| Subject: Threading problem with Managed Extensions
| Date: Mon, 13 Oct 2003 09:14:59 -0700
| Lines: 10
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcORpSYVXmtEPFysQ9CAztCKDGGjzA==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54331
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a Windows Form developed in C# using the Microsoft
| Web Browser control, which is an old-style COM control.
| When I run the form from a .NET application that has an
| [STAThread] attribute on the startup object, it works
| fine. However, when I run the same form from a C++
| application using Managed Extensions for C++, I
| get "Server Busy" messages when the message loop blocks. I
| believe I need to indicate somehow to the Managed
| Extensions that I want to run the code in an STA. How do I
| do that?
|

.
 
Back
Top