Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 22nd, 2008, 12:49 PM
Authorized User
 
Join Date: Apr 2005
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old January 22nd, 2008, 01:22 PM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
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 ;)

Reply With Quote
  #3 (permalink)  
Old January 22nd, 2008, 01:29 PM
Authorized User
 
Join Date: Apr 2005
Location: , , .
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
Reply With Quote
  #4 (permalink)  
Old January 23rd, 2008, 04:34 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
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...

Reply With Quote
  #5 (permalink)  
Old January 23rd, 2008, 05:22 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
Reply With Quote
  #6 (permalink)  
Old January 23rd, 2008, 05:29 AM
Authorized User
 
Join Date: Apr 2005
Location: , , .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.