473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Scripting in .Net using CodeDom

I have been testing various techniques to run "script" code which will
be stored in a SQL database and executed dynamically at runtime. The
scripts are essentially business rules that result in a report being
generated based on test parameters input by a user - 4 batches of
scripts containing multiple functions will be run each time a user runs
a new test. The reason the scripts are run in 4 batches is due to the
fact that each batch is built upon the results of the prior batch. I
have been leaning towards a VB type language since it is well known and
supports the type of functionality required.

Since the application is being written in .Net my initial thought was
to use VSA. Using this technique I was running into serious memory
leaks (on the order of 1M for each batch of scripts) on each test run.
Next I switched to manually using CodeDom and creating a new AppDomain
for each batch of scripts using a class factory approach. This worked
much better, but still results in leaking about 400 bytes for each
batch of scripts run. Plus I could only run about 6 batches of scripts
per second. Following are the compiler parameters being set which are
meant to be as efficient as possible:

CompilerParameters cParams = new CompilerParameters();
cParams.CompilerOptions = "/target:library /optimize";
cParams.GenerateExecutable = false;
cParams.GenerateInMemory = true;
cParams.IncludeDebugInformation = false;

After a lot of testing and debate I decided to test out using the
Microsoft Script Control. The results were over 300 times faster
(2,887 batches of scripts per second versus 6) with no memory leaks.
Following is a sample of what I put into a test loop:

MSScriptControl.ScriptControl sc = new
MSScriptControl.ScriptControlClass();

sc.Language = "VBScript";
sc.AddCode(TestCOMScript);

Object[] oParams = new Object[2] { new Random().Next(1000), new
Random().Next(1000) };
sc.Run("GetNumber", ref oParams).ToString();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(sc);

The decision seems to be a no-brainer, but I wanted to see if anyone
has an idea of how this can be accomplished using only managed code but
without such a large performance hit or the memory leaks. I really
hate to use an ActiveX object on an otherwise purely managed
application.

Nov 16 '05 #1
1 5539
Hi Fred!

This is exactly why I've started to write a purely managed scripting engine
for .NET. Microsoft has, for some unknown reasons, forsaken the interpreting
script support and forces us to compile everything instead (which is
completely unnecessary when you want to execute dynamic code). Or at least
I'm not aware of any managed way to execute code dynamically without
compiling.

BTW., I've finally found some time to get back to my scripting library (I've
announced it some time ago), so some early bits should be available soon.

Stefan

<fr*********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I have been testing various techniques to run "script" code which will
be stored in a SQL database and executed dynamically at runtime. The
scripts are essentially business rules that result in a report being
generated based on test parameters input by a user - 4 batches of
scripts containing multiple functions will be run each time a user runs
a new test. The reason the scripts are run in 4 batches is due to the
fact that each batch is built upon the results of the prior batch. I
have been leaning towards a VB type language since it is well known and
supports the type of functionality required.

Since the application is being written in .Net my initial thought was
to use VSA. Using this technique I was running into serious memory
leaks (on the order of 1M for each batch of scripts) on each test run.
Next I switched to manually using CodeDom and creating a new AppDomain
for each batch of scripts using a class factory approach. This worked
much better, but still results in leaking about 400 bytes for each
batch of scripts run. Plus I could only run about 6 batches of scripts
per second. Following are the compiler parameters being set which are
meant to be as efficient as possible:

CompilerParameters cParams = new CompilerParameters();
cParams.CompilerOptions = "/target:library /optimize";
cParams.GenerateExecutable = false;
cParams.GenerateInMemory = true;
cParams.IncludeDebugInformation = false;

After a lot of testing and debate I decided to test out using the
Microsoft Script Control. The results were over 300 times faster
(2,887 batches of scripts per second versus 6) with no memory leaks.
Following is a sample of what I put into a test loop:

MSScriptControl.ScriptControl sc = new
MSScriptControl.ScriptControlClass();

sc.Language = "VBScript";
sc.AddCode(TestCOMScript);

Object[] oParams = new Object[2] { new Random().Next(1000), new
Random().Next(1000) };
sc.Run("GetNumber", ref oParams).ToString();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(sc);

The decision seems to be a no-brainer, but I wanted to see if anyone
has an idea of how this can be accomplished using only managed code but
without such a large performance hit or the memory leaks. I really
hate to use an ActiveX object on an otherwise purely managed
application.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: darren | last post by:
I have a mature C/C++ application to which I am wanting to add custom delevopment/scripting capabilities. Initially this will be used as part of a testing framework. It appears to me that VBA...
4
by: Michael Andersson | last post by:
Hi! I'm writing a small game engine in c# and I'm in great need of a scripting language. Does anyone know of such a language? Would it be possible to use the VSA in some way to do this? Best...
1
by: Pardhasaradhy | last post by:
Hi, Please see the following error and revert back as early as possible. I am getting this once I request for the asp.net page. Server Error in '/tanishq' Application. Timed out waiting for...
0
by: Marco Viana | last post by:
Hi, I'm developing an ASP.NET application with Visual Studio .NET 2003 in a Win XP Professional, .NET Framework 1.1 and IIS 5.1 computer with all the lattest patches. When testing a page...
9
by: lee.chappers | last post by:
How can I make the CodeDom generate the following C# method? protected sealed override void Test() { } I've tried using: domMethod.Attributes = MemberAttributes.Override |...
1
by: VJ | last post by:
Is CodeDom the recomended way to make scripting available in a windows application or using MSscript activex/com control ok? Right now we want to offer basic functions or simple if then else logic,...
6
by: moondaddy | last post by:
will CodeDom create XAML windows or just regular windows forms? If so, how to I tell it to create a xaml window instead of a windows form? thanks -- moondaddy@noemail.noemail
4
by: Chizl | last post by:
I'm developing a C# web server and I want to implement some kind of server side scripting. I thought about writing my own, but that will take some time.. I'm not sure if there is a way to...
3
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, I've come to the conclusion that a scripting language will make a fine solution for a feature that I want to program for an app. I do not expect any problems parsing the script the old...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.