Code Red > .NET
make a program running immediatly at the first execution
samideqlqpart:
hello
my problem is
when i lunch my plug-in in autocad for the first time, it takes a long time to execute
but after and at every time it takes a very short moment
it seems that something is stoked in the RAM.i don't know wich element
my question : what can i do to make my program running immediatly at the first call
thank you
Atook:
Sounds to me like you're loading a large array or list when loading the DLL? Maybe from a database/text file?
You could start using a timer to troubleshoot where the problem is.
Something like:
--- Code - C#: ---Stopwatch timer = Stopwatch.StartNew();// do stufftimer.Stop();Debug.Writeline($"Elapsed time: {timer.ElapsedMilliseconds} ms.");
Once you've figured out where the problem is, you can optimize it, and decide if you want it called in the Inititalize() event of the IExtensionApplication, or when your code is actually called by the user.
samideqlqpart:
i've translated it to vb.net
Dim timer As Stopwatch = Stopwatch.StartNew()
' do stuff
timer.[Stop]()
Debug.Writeline("Elapsed time: {timer.ElapsedMilliseconds} ms.")
1-where do i have to past this code?
2-what the code do?
Atook:
That code wraps around various elements of your code that are initializing things. The Debug.Print statement will tell you how how long it took. You will see it in the output window of Visual studio when you debug your code.
--- Code - C#: ---Stopwatch dbTimer= Stopwatch.StartNew();// do load databasedbTimer.Stop();Debug.Writeline($"Loading Database, elapsed time: {dbTimer.ElapsedMilliseconds} ms.");...Stopwatch layerTimer= Stopwatch.StartNew();// do Layer CreationlayerTimer.Stop();Debug.Writeline($"Creating Layers, elapsed time: {layerTimer.ElapsedMilliseconds} ms.");
When this code gets called you might see something like this in the output window of your IDE while debugging:
--- Code: ---Loading Database, elapsed time: 5042 ms.
Creating Layers, elapsed time: 15 ms.
--- End code ---
That would tell you that the delay is loading the database, and you can decide how to change it, or where to put it.
I'm not familiar with the VB.NET IExtensionApplication.Initialize event is, but that's where you put code that runs when your app is loaded. If you were calling the loaddatabase in that function you'd see a pause when your app was first loaded into memory. If you were calling loaddatabase in some other command you created, you'd see the pause then.
samideqlqpart:
i see nothing :crazy2:
but i can't change anything cause my program is established
perhaps i reserved a large array dim... dim..... at the begin
but how to explain that in the second uses it's fast than the first run
Navigation
[0] Message Index
[#] Next page
Go to full version