Re: Application consumes close to 100% of CPU, how to profile and determine the cause
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 14 Oct 2005 16:24:17 -0400
From what I can see, you don't need to pin the byte array before passing
it to your unamanged code. The marshaler will pin the array in memory for
you, and release it when done.
As for the spike, there is nothing here that I would see that would
cause this, as you are releasing the pinned variable. Does your application
not respond during this time? You haven't given any indication that 100%
utilization is impacting your app, or the machine negatively.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
<LordHog@xxxxxxxxxxx> wrote in message
news:1129319466.376153.201080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Nicholas,
>
> Sorry that I didn't explain myself well enough. Actually when the
> process consumes close to 100% of the CPU it stays at that level until
> I kill the task. I have let it run a few minutes to see if it would
> recover, but it never did so I killed the task. I am unclear what is
> triggering it.
>
> For the P/Invoke functions they look like the following
>
> [DllImport("SiF32xUSB.DLL", EntryPoint = "F32x_Write", SetLastError
> = true,
> CharSet = CharSet.Unicode, ExactSpelling = true,
> CallingConvention = CallingConvention.StdCall)]
> private static extern
> System.Int32 F32x_Write( System.UInt32 Handle,
> System.IntPtr Buffer,
> System.UInt32 NumBytesToRead,
> ref System.UInt32
> NumBytesWrittenToDevice
> );
>
> Then the correspond method that uses this function is as follows:
>
> public bool Write( UInt32 handle, byte[] buffer )
> {
> UInt32 numBytesWritten = 0x00;
>
> GCHandle gch = GCHandle.Alloc( buffer, GCHandleType.Pinned );
>
> m_LastErrorCode =
> (SI_RETURN_CODES)F32x_Write( handle,
> gch.AddrOfPinnedObject(),
> (UInt32)buffer.Length,
> ref numBytesWritten );
>
> gch.Free();
>
> if ( m_LastErrorCode == SI_RETURN_CODES.SI_SUCCESS )
> {
> return true;
> }
> else
> {
> return false;
> }
> }
>
> I don't know if either of these declarations are causing the problems
> or not. I did notice I do have one P/Invoke function to where the
> memory isn't pinned therefore perhaps the GC is executing at that
> particular time and causing the problem. That method looks like
>
> public MMCThermocoupleTypes TCType
> {
> get { return m_TCType; }
> set
> {
> int apiResult;
>
> try
> {
> m_TCType = value;
> apiResult = cbSetConfig( (int)MCCCfgInfpType.BOARDINFO,
> (int)m_USBTCBoardNum,
> (int)m_ChamberTCChannel,
>
> (int)MMMBoardCfgInfoType.BITCCHANTYPE,
> (int)m_TCType
> );
> }
> catch ( Exception )
> {
> // TODO: Implement handler for this event.
> }
> }
> }
>
> The variables that start with "m_" are members to the class and are
> private. Perhaps the GC is moving memory around at this particular
> point in time causing problems? I really don't know.
>
> Mark
>
.
- References:
- Prev by Date: Re: Strong Typed Collections
- Next by Date: Re: test
- Previous by thread: Application consumes close to 100% of CPU, how to profile and determine the cause
- Next by thread: Re: Application consumes close to 100% of CPU, how to profile and determine the cause
- Index(es):
Relevant Pages
|