Question Running vb code on the fly

jackgreat

Active member
Joined
Apr 17, 2006
Messages
35
Programming Experience
1-3
Hello Guys,

I wanted to provide programming support for an application I made. So I used System.CodeDom compiler and it allows me to execute vb.net code on the fly.

The way it works is :

- I call the engine and pass references and code that it needs to run
- The code is able to access public subs
- results are obtained after processing completes.

Lets assume I have a module called RunCode which runs user code.

VB.NET:
Public Module RunCode

Friend Age as integer

Sub Run()
' executing user code
' init script
        Script.Imports.Add("Microsoft.VisualBasic")
        Script.Imports.Add("System.IO")

        Script.Imports.Add("MyApp.Module1")

     results =  Script.CompileAssemblyFromSource(parameter, usercode)

End Sub

End Module

Public Module Module1

Sub Age(ByVal A as Integer)
Age = A + 10
End Sub

End Module

I want that if the code is being executed by user on seperate threads at the same time then their values should be independant. Right now this is not possible as module has been used and not classes.

What I want is -> create object of class RunCode, it runs user code and returns. Thus the age variable in class runcode is not tampered with if at the same time another code is executed. But for that module module1 has to be a class also and how can user call Age sub if its a class. I mean user should be able to call all subs/functions by name and it should work like it was working right now.

Will be glad if anyone can help me out. (Info on running such code : Compiling .NET code on-the-fly - CodeProject®)

Thanks,

Cheers,
Jack
 
Back
Top