CreateApplicationContext thread take 50% cpu

D

Droopy

Hi,

When I start my application, I notice that it takes 50% CPU in idle status
!
I used Process Explorer from Sysinternals to find what thread is consuming
that much CPU.
Only 1 thread is consuming the whole 50% : "mscorwks.dll!
CreateApplicationContext".

To be complete :
.. I am using VS2005 (=> dotnet framework 2.0)
.. my application is calling a dll written in C# dotnet framework 1.1 that
is a wrapper for C++ legacy code handling a serial port
.. my application previous version written in dotnet framework 1.1 used the
same wrapper code (but not via a dll), cpu was almost 0 in this case.

Thanks a lot in advance for your help.

Droopy.
 
W

Willy Denoyette [MVP]

| Hi,
|
| When I start my application, I notice that it takes 50% CPU in idle status
| !
| I used Process Explorer from Sysinternals to find what thread is consuming
| that much CPU.
| Only 1 thread is consuming the whole 50% : "mscorwks.dll!
| CreateApplicationContext".
|
| To be complete :
| . I am using VS2005 (=> dotnet framework 2.0)
| . my application is calling a dll written in C# dotnet framework 1.1 that
| is a wrapper for C++ legacy code handling a serial port
| . my application previous version written in dotnet framework 1.1 used the
| same wrapper code (but not via a dll), cpu was almost 0 in this case.
|
| Thanks a lot in advance for your help.
|
| Droopy.


Do you mean that your application keeps consuming 50% of the CPU while
executing the CreateApplicationContext function?
What happens if you compile your wrapper DLL using vs2005?

Willy.
 
D

Droopy

| Hi,
|
| When I start my application, I notice that it takes 50% CPU in idle
| status !
| I used Process Explorer from Sysinternals to find what thread is
| consuming that much CPU.
| Only 1 thread is consuming the whole 50% : "mscorwks.dll!
| CreateApplicationContext".
|
| To be complete :
| . I am using VS2005 (=> dotnet framework 2.0)
| . my application is calling a dll written in C# dotnet framework 1.1
| that is a wrapper for C++ legacy code handling a serial port
| . my application previous version written in dotnet framework 1.1
| used the same wrapper code (but not via a dll), cpu was almost 0 in
| this case.
|
| Thanks a lot in advance for your help.
|
| Droopy.


Do you mean that your application keeps consuming 50% of the CPU while
executing the CreateApplicationContext function?

Yes !
What happens if you compile your wrapper DLL using vs2005?

Well I don't know !
I compiled it in vs2003 because the C++ wrapper did not compile in
vs2005.
It seems there are a lot of changes concerning C++ managed extensions and
I did not have enough time to port it (at least I expected it to be non
easy).

Thanks a lot for your help.
 
W

Willy Denoyette [MVP]

| |
| >
| > | >| Hi,
| >|
| >| When I start my application, I notice that it takes 50% CPU in idle
| >| status !
| >| I used Process Explorer from Sysinternals to find what thread is
| >| consuming that much CPU.
| >| Only 1 thread is consuming the whole 50% : "mscorwks.dll!
| >| CreateApplicationContext".
| >|
| >| To be complete :
| >| . I am using VS2005 (=> dotnet framework 2.0)
| >| . my application is calling a dll written in C# dotnet framework 1.1
| >| that is a wrapper for C++ legacy code handling a serial port
| >| . my application previous version written in dotnet framework 1.1
| >| used the same wrapper code (but not via a dll), cpu was almost 0 in
| >| this case.
| >|
| >| Thanks a lot in advance for your help.
| >|
| >| Droopy.
| >
| >
| > Do you mean that your application keeps consuming 50% of the CPU while
| > executing the CreateApplicationContext function?
|
| Yes !
|

Well, that would mean that this function never returns, more, it loops
endlessly, which IMO is not quite possible. Only possible way to know for
sure what's happening is to attach a debugger (native mode).

Willy.
 
D

Droopy

| |
| >
| > | >| Hi,
| >|
| >| When I start my application, I notice that it takes 50% CPU in
| >| idle status !
| >| I used Process Explorer from Sysinternals to find what thread is
| >| consuming that much CPU.
| >| Only 1 thread is consuming the whole 50% : "mscorwks.dll!
| >| CreateApplicationContext".
| >|
| >| To be complete :
| >| . I am using VS2005 (=> dotnet framework 2.0)
| >| . my application is calling a dll written in C# dotnet framework
| >| 1.1 that is a wrapper for C++ legacy code handling a serial port
| >| . my application previous version written in dotnet framework 1.1
| >| used the same wrapper code (but not via a dll), cpu was almost 0
| >| in this case.
| >|
| >| Thanks a lot in advance for your help.
| >|
| >| Droopy.
| >
| >
| > Do you mean that your application keeps consuming 50% of the CPU
| > while executing the CreateApplicationContext function?
|
| Yes !
|

Well, that would mean that this function never returns, more, it loops
endlessly, which IMO is not quite possible. Only possible way to know
for sure what's happening is to attach a debugger (native mode).

Willy.

Not sure I understand !
I didn't call this function so how can I check if it returns ?
By the way, I have the whole source code so I can start the application
in debug mode in vs2005.
Should I put a breakpoint somewhere ?
 
W

Willy Denoyette [MVP]

| |
| >
| > | >| | >|
| >| >
| >| > | >| >| Hi,
| >| >|
| >| >| When I start my application, I notice that it takes 50% CPU in
| >| >| idle status !
| >| >| I used Process Explorer from Sysinternals to find what thread is
| >| >| consuming that much CPU.
| >| >| Only 1 thread is consuming the whole 50% : "mscorwks.dll!
| >| >| CreateApplicationContext".
| >| >|
| >| >| To be complete :
| >| >| . I am using VS2005 (=> dotnet framework 2.0)
| >| >| . my application is calling a dll written in C# dotnet framework
| >| >| 1.1 that is a wrapper for C++ legacy code handling a serial port
| >| >| . my application previous version written in dotnet framework 1.1
| >| >| used the same wrapper code (but not via a dll), cpu was almost 0
| >| >| in this case.
| >| >|
| >| >| Thanks a lot in advance for your help.
| >| >|
| >| >| Droopy.
| >| >
| >| >
| >| > Do you mean that your application keeps consuming 50% of the CPU
| >| > while executing the CreateApplicationContext function?
| >|
| >| Yes !
| >|
| >
| > Well, that would mean that this function never returns, more, it loops
| > endlessly, which IMO is not quite possible. Only possible way to know
| > for sure what's happening is to attach a debugger (native mode).
| >
| > Willy.
| >
| >
| >
|
| Not sure I understand !
| I didn't call this function so how can I check if it returns ?
| By the way, I have the whole source code so I can start the application
| in debug mode in vs2005.
| Should I put a breakpoint somewhere ?

Ok, I suppose that your application doesn't run, right? That means it's
looping indefinitely without ever doing what it is supposed to do. If this
is not the case forget all that follows, and forget about Process explorer,
use a debugger or permon to watch CPU consumption, PE is not the right tool
for this.

Now, CreateApplicationContext is called by Fusion whenever classes are to be
loaded in an AD. So it can happen very early in the process when the CLR
loads system classes into the shared domain, that is before the JIT is
loaded. However I don't believe this is the case here.

The only way to set a breakpoint at mscorwks!CreateApplicationContext, is by
starting the application in an unmanaged debugger like Windbg. All you need
is a correct setup of the debugger environment and the symbol files.

But before you go down that route, run the application in the VS debugger,
if the function doesn't return (which I doubt) the application will loop, so
when you break you are sure you are in the mscorwks!CreateApplicationContext
native code (make sure you have the symbol path set to the symbol server -
http://msdl.microsoft.com/download/symbols ) and you can single step and
watch if it's effectively looping, if it does you will need to be a debugger
expert to be able to draw a conclusion.
Therefore I would suggest you take a close look at your code, compile the
wrapper using VS2005 and try again.


Willy.
 
D

Droopy

| |
| >
| > | >| | >|
| >| >
| >| > | >| >| Hi,
| >| >|
| >| >| When I start my application, I notice that it takes 50% CPU in
| >| >| idle status !
| >| >| I used Process Explorer from Sysinternals to find what thread
| >| >| is consuming that much CPU.
| >| >| Only 1 thread is consuming the whole 50% : "mscorwks.dll!
| >| >| CreateApplicationContext".
| >| >|
| >| >| To be complete :
| >| >| . I am using VS2005 (=> dotnet framework 2.0)
| >| >| . my application is calling a dll written in C# dotnet
| >| >| framework 1.1 that is a wrapper for C++ legacy code handling a
| >| >| serial port . my application previous version written in dotnet
| >| >| framework 1.1 used the same wrapper code (but not via a dll),
| >| >| cpu was almost 0 in this case.
| >| >|
| >| >| Thanks a lot in advance for your help.
| >| >|
| >| >| Droopy.
| >| >
| >| >
| >| > Do you mean that your application keeps consuming 50% of the CPU
| >| > while executing the CreateApplicationContext function?
| >|
| >| Yes !
| >|
| >
| > Well, that would mean that this function never returns, more, it
| > loops endlessly, which IMO is not quite possible. Only possible way
| > to know for sure what's happening is to attach a debugger (native
| > mode).
| >
| > Willy.
| >
| >
| >
|
| Not sure I understand !
| I didn't call this function so how can I check if it returns ?
| By the way, I have the whole source code so I can start the
| application in debug mode in vs2005.
| Should I put a breakpoint somewhere ?

Ok, I suppose that your application doesn't run, right?

No, it runs very well.
That means it's looping indefinitely without ever doing what it is supposed to
do. If this is not the case forget all that follows, and forget about
Process explorer, use a debugger or permon to watch CPU consumption,
PE is not the right tool for this.

I used PE just to know which threads were consuming CPU but may be the
informations are not accurate.
Anyway%, both TaskManager and PE reports 50% cpu for the process.
Did you mean perfmon ?
I tried with it.
Not sure to use in the appropriate way.
I choose Thread/% Processor Time and one by one my application threads
until i choose one thread that report an average of 99,605 % !
I suppose is not % because task manager reports 50% cpu for the
application.
I can also run it into WinDbg but when I choose View/Processes and Threads,
the window is empty.

May be the best would be to try to recompile my application in vs2003
1) using my wrapper DLL
2) not using DLL (using the wrapper project)
 
D

Droopy

May be the best would be to try to recompile my application in vs2003
1) using my wrapper DLL
2) not using DLL (using the wrapper project)

I did it and still 50% CPU but this time PE reports it in mscorwks.dll!
ReleaseFusionInterfaces.

I made a new solution in vs2003 with 2 projects :
1) WinForm ported from vs2005
2) the wrapper project (not the dll).

So it seems that it is not linked to the wrapper project/dll because using
this same project wrapper in my previous program developped in vs2003 use
0% CPU.
Still, if I configure my application for not using serial ports (handled in
this wrapper project), the CPU usage is 0% !

I am puzzled.
 
W

Willy Denoyette [MVP]

|> May be the best would be to try to recompile my application in vs2003
| > 1) using my wrapper DLL
| > 2) not using DLL (using the wrapper project)
| >
|
| I did it and still 50% CPU but this time PE reports it in mscorwks.dll!
| ReleaseFusionInterfaces.
|

That's the last function called by fusion, but that doesn't mean this
function is still running.


| I made a new solution in vs2003 with 2 projects :
| 1) WinForm ported from vs2005
| 2) the wrapper project (not the dll).
|
| So it seems that it is not linked to the wrapper project/dll because using
| this same project wrapper in my previous program developped in vs2003 use
| 0% CPU.
| Still, if I configure my application for not using serial ports (handled
in
| this wrapper project), the CPU usage is 0% !
|
| I am puzzled.


Well, it looks like the Serial port C++ code is the culprit, apparently this
code runs on a thread other than the main thread (one that you created),
this one is in a tied loop. You don't call C functions in a loop don't you?

Willy.
 
D

Droopy

|> May be the best would be to try to recompile my application in
|> vs2003
| > 1) using my wrapper DLL
| > 2) not using DLL (using the wrapper project)
| >
|
| I did it and still 50% CPU but this time PE reports it in
| mscorwks.dll! ReleaseFusionInterfaces.
|

That's the last function called by fusion, but that doesn't mean this
function is still running.


| I made a new solution in vs2003 with 2 projects :
| 1) WinForm ported from vs2005
| 2) the wrapper project (not the dll).
|
| So it seems that it is not linked to the wrapper project/dll because
| using this same project wrapper in my previous program developped in
| vs2003 use 0% CPU.
| Still, if I configure my application for not using serial ports
| (handled
in
| this wrapper project), the CPU usage is 0% !
|
| I am puzzled.


Well, it looks like the Serial port C++ code is the culprit,
apparently this code runs on a thread other than the main thread (one
that you created), this one is in a tied loop. You don't call C
functions in a loop don't you?

Willy.

No it can't because the same C++ code is executed in both version from my
application.
I added a lot of monitoring and finally found the bug :)
Each time a message come from the serial line, I insert it in a queue to
give control back as soon as possible to calling thread.
Another thread is reading the queue and handle messages.
This handling is controlled by a ManualResetEvent.
Due to a bad indentation, this event was never Reset (Reset was just
outside the main loop) so the main loop was consuming all the CPU.

Anyway, thanks a lot for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top