473,385 Members | 1,647 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,385 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 5535
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.