Moderator: xxSlayeRxx
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
// INSTRUKCJA
//http://www.codeproject.com/Tips/715891/Compiling-Csharp-Code-at-Runtime
namespace enigma_engine2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string code0 = @"
using System;
using System.Collections.Generic;
using System.Collections;
namespace First
{
public class Program
{
public static void Main()
{
}
public static Hashtable engine(Hashtable a)
{
Hashtable ret=new Hashtable();;
for (;;)
{
System.Threading.Thread.Sleep(1000);
// @@ Tu zdało by się odpalić zdażenie w moim Form'ie <----------------------------<------------<
}
ret.Add(1, a);
return ret;
}
}
}
";
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateInMemory = true;
parameters.GenerateExecutable = true;
CompilerResults results = provider.CompileAssemblyFromSource(parameters, code0);
if (results.Errors.HasErrors)
{
StringBuilder sb = new StringBuilder();
foreach (CompilerError error in results.Errors)
{
sb.AppendLine(String.Format("Error ({0}): {1}", error.ErrorNumber, error.ErrorText));
}
throw new InvalidOperationException(sb.ToString());
}
System.Reflection.Assembly assembly = results.CompiledAssembly;
Type program = assembly.GetType("First.Program");
System.Reflection.MethodInfo engine = program.GetMethod("engine");
System.Reflection.MethodInfo getKomunikat = program.GetMethod("getKomunikat");
//DelegatDoRaportowanie_znaleziska Handler = Raportowanie_znaleziska;
object[] parametry = new object[] { new Hashtable() };
Hashtable i = (Hashtable)engine.Invoke(this, parametry);
object iw = getKomunikat.Invoke(this, new object[] { });
}
public static void mojEvent()
{
//@@ Tu chce być jak program skąpilowany przerobi część zadania !! <----------------------<
}
}
}
Użytkownicy przeglądający ten dział: Bing [Bot] i 14 gości