|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Macros too slow !I posted this topic in microsoft.public.dotnet.general but received no reply. So hoping for a reply here... I'm trying to use a macro in VS 2003 to insert a code snippet in various sections of my code. This code will help me to test the time taken for any particular action to be performed. The problem is that it takes nearly 30 seconds for it to be executed, after I press my Keyboard shortcut, and to see the results in my code window. I'm new to using macros in the IDE, so I have no idea if the macro is actually being compiled and then executed or what ! The macro code is as follows : ========================= Sub TimeSpanCheck() Dim objDoc As Document = DTE.ActiveDocument Dim mySel As TextSelection = objDoc.Selection mySel.Text = "Console.Write(""Time before the action :"")" mySel.NewLine() mySel.Text = "Dim oldTime As DateTime = DateTime.Now" mySel.NewLine() mySel.Text = "Console.WriteLine(""{0:HH:mm:ss.fff}"", oldTime)" mySel.NewLine() mySel.Text = " ' " mySel.NewLine() mySel.Text = " ' My actions here" mySel.NewLine() mySel.Text = " ' " mySel.NewLine() mySel.Text = "Console.Write(""Time after the action :"")" mySel.NewLine() mySel.Text = "Dim newTime As DateTime = DateTime.Now" mySel.NewLine() mySel.Text = "Console.WriteLine(""{0:HH:mm:ss.fff}"", newTime)" mySel.NewLine() mySel.Text = "Dim Diff As TimeSpan = newTime.Subtract(oldTime)" mySel.NewLine() mySel.Text = "Console.WriteLine(""Time taken for process : {0}min:{1}secs:{2}millisecs"", Diff.Minutes, Diff.Seconds, Diff.Milliseconds)" mySel.NewLine() objDoc.Save() End Sub ========================= Am I doing something wrong here, or is this time taken normal ? Also, is there a way to speed it up (something like precompiling the code.) Any comments are appreciated, Regards, Cerebrus. Hi,
You are using TextSelection.Text property to insert the text. This may be the reason of slow execution. The better way is to use TextSelection.Insert method. See my blog on VS macros at http://www.vbdocman.com/blog/archives/14. This article contains very simple macro which inserts some code at the current cursor position. In addition it correctly handles Undo operation. It executes immediately. FYI, you can find more responses about for VS add-ins and macros in microsoft.public.vb.addins. -- Peter Macej Helixoft - http://www.vbdocman.com VBdocman - Automatic generator of technical documentation for VB, VB ..NET and ASP .NET code Hi Peter,
AFAIK, microsoft.public.vb.addins is for VB6 add-ins, not for VS.NET add-ins. I used to answer questions in that newsgroup long time ago... -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Peter Macej" <pe***@vbdocman.com> escribió en el mensaje news:%231ElauPQGHA.4084@TK2MSFTNGP10.phx.gbl... > Hi, > > You are using TextSelection.Text property to insert the text. This may be > the reason of slow execution. The better way is to use > TextSelection.Insert method. See my blog on VS macros at > http://www.vbdocman.com/blog/archives/14. This article contains very > simple macro which inserts some code at the current cursor position. In > addition it correctly handles Undo operation. It executes immediately. > > FYI, you can find more responses about for VS add-ins and macros in > microsoft.public.vb.addins. > > > -- > Peter Macej > Helixoft - http://www.vbdocman.com > VBdocman - Automatic generator of technical documentation for VB, VB .NET > and ASP .NET code Wow ! Thanks a lot, Peter.
After checking your sample, I realized that I could use all the Framework classes here. So I used a StringBuilder to build up the Code fragment and then used ONE insert statement only. I also learnt how to use Undo. Now it works, and it is instantaneous ! ;-) Thanks again, Regards, Cerebrus.
Treeview population directly from MSAccess
Is there an expected return difference between the following two codes Datagrid with comboboxes storing mysql data to a random access file debug problem Excel.application How to have the same info on two menus Error Message Form resizing on different machines VB.NET 2003 SMTP question with Vb.net 2003 |
|||||||||||||||||||||||