Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2008, 12:49 PM
Authorized User
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default .Net do not use all the cpu calling to C++ DLL

I have a small aplication in windows forms (C# framework 2.0) which call in a loop to a function of a C++ Dll. I have the same aplication done in VB6, and VB6 goes quite a lot quicker than C# aplication, 10 times more quickly more or less.

When the application in VB6 is running I can see in Task manager It is using 50% of CPU more less. But When I run the application in C# doing the same It is using only 5% of CPU.

It only happnes when I call to this dll, other applications in C# use 50% of CPU too in large loops.

Do you know the reason?

Thanks in advance




http://www.hhdirecto.net
http://www.dechiste.com
http://www.sinmp3.com
__________________
http://www.terapiahiphop.com
 
Old January 22nd, 2008, 01:22 PM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you give sample of your code how you call the DLL in C# and what the actual C++ class/method/function/whatever looks like? I'm guessing that .NET is creating and destroying that C++ object when it is running inside the loop.

50% CPU time... It seems you are running double core CPU. Create two threads to run loops and you get nice round 100% CPU usage if you make sure they are ran on separate cores ;)

 
Old January 22nd, 2008, 01:29 PM
Authorized User
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the loop
Code:
            
for (int step = 0; step < steps ; step++)
            {
                simulator.Run(step + 1);

            }


Yes it is a dual core CPU. It is not important in this case to use 100%, but It is important to me to use 50% and not 5%.

Thanks

http://www.hhdirecto.net
http://www.dechiste.com
http://www.sinmp3.com
 
Old January 23rd, 2008, 04:34 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, that 100% was just a joke :)

But that piece of code destroyed my nice little theory so I'm all out of ideas. I hope that someone else has more insight on this one...

 
Old January 23rd, 2008, 05:22 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

How are you declaring the call to the DLL? Are you using p/invoke or are you using COM interop?

If the former, then can you show us the declaration in both the C# example, and the old VB6 example.

/- Sam Judson : Wrox Technical Editor -/
 
Old January 23rd, 2008, 05:29 AM
Authorized User
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

****** VB ***

I added the COM dll in references and then:
        Dim simulator As MySimulator
        Set simulator = New MySimulator

********** C# ********
I add the COM dll in references an then:

            MySimulatorLib.MySimulator simulator;
            simulator = new MySimulator.MySimulator ();



After that I only initializate some parameters of the dll like
simulator.parameter1 = 3;
simulator.parameter2 = x;

And then I run the loop calling to run() functión of the DLL

Thanks

http://www.hhdirecto.net
http://www.dechiste.com
http://www.sinmp3.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a method defined inside a .NET dll rajen C# 5 January 7th, 2008 04:04 AM
Calling VB.Net Dll from Excel VBA zyphax Pro VB.NET 2002/2003 4 July 16th, 2007 08:41 PM
Calling a method defined inside a .NET dll rajen C# 2005 0 September 19th, 2006 12:58 AM
Calling a .Dll of Vb.NET enggalok C++ Programming 0 March 1st, 2004 06:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.