473,804 Members | 4,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:

CompilerParamet ers cParams = new CompilerParamet ers();
cParams.Compile rOptions = "/target:library /optimize";
cParams.Generat eExecutable = false;
cParams.Generat eInMemory = true;
cParams.Include DebugInformatio n = 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 .ScriptControlC lass();

sc.Language = "VBScript";
sc.AddCode(Test COMScript);

Object[] oParams = new Object[2] { new Random().Next(1 000), new
Random().Next(1 000) };
sc.Run("GetNumb er", ref oParams).ToStri ng();

System.Runtime. InteropServices .Marshal.Releas eComObject(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 5571
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*********@ya hoo.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.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:

CompilerParamet ers cParams = new CompilerParamet ers();
cParams.Compile rOptions = "/target:library /optimize";
cParams.Generat eExecutable = false;
cParams.Generat eInMemory = true;
cParams.Include DebugInformatio n = 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 .ScriptControlC lass();

sc.Language = "VBScript";
sc.AddCode(Test COMScript);

Object[] oParams = new Object[2] { new Random().Next(1 000), new
Random().Next(1 000) };
sc.Run("GetNumb er", ref oParams).ToStri ng();

System.Runtime. InteropServices .Marshal.Releas eComObject(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
1976
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 has been replaced with the .NET environment, and I am interested in what tools are available for creating such a development environment (eg generating a custom IDE) and a list of the basic interfaces that the existing app would need to support...
4
4428
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 regards, /Michael
1
6484
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 a program to execute. The command being executed was "c:\winnt\microsoft.net\framework\v1.0.3705\vbc.exe"
0
2862
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 sometimes i get the following error. Does anyone knows what i have to do to get rid of this error?
9
3984
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 | MemberAttributes.Family | MemberAttributes.Final;
1
1437
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, in future we plan to make a full scripting language available like with MS Excel or MS Word. Would going CodeDom way be better now?.. VJ
6
5771
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
2242
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 impliment something someone already has. Anyone have any experience with any of this and willing to provide me a starting point?
3
4684
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 fashion way by manually searching the string. However, if there are good tools - tutorials - on the matter I would like to know about it. I've come across the Regex functionality, I guess it could be used - but to what extent.
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10320
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7620
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.