예제 #1
0
 public void Dispose()
 {
     _runSourceInitEndMethods.CallEndMethods();
     if (_currentRunSource == this)
     {
         _currentRunSource = null;
     }
     DisposeData();
     if (gdtResult != null)
     {
         gdtResult.Dispose();
         gdtResult = null;
     }
     AssemblyResolve.Stop();
     //_trace.Writed -= new WritedEvent(EventWrited);
 }
예제 #2
0
        private void RunCode_v1(string code, bool useNewThread = true, bool compileWithoutProject = false)
        {
            if (code == "")
            {
                return;
            }

            bool bError = false;

            if (_runCodeThread != null)
            {
                throw new PBException("error program already running");
            }

            bool bOk = false;

            _runCodeChrono = new Chrono();
            try
            {
                AssemblyResolve.Stop();
                AssemblyResolve.Clear();

                _refreshRunSourceConfig = true;
                _refreshProjectConfig   = true;

                IGenerateAndExecute generateAndExecute = GetGenerateAndExecuteManager().New();
                _GenerateCodeAndCompile_v2(generateAndExecute, code, compileWithoutProject);
                if (generateAndExecute.Compiler.HasError())
                {
                    return;
                }

                MethodInfo runMethod  = generateAndExecute.GetAssemblyRunMethod();
                MethodInfo initMethod = generateAndExecute.GetAssemblyInitMethod();
                MethodInfo endMethod  = generateAndExecute.GetAssemblyEndMethod();

                AssemblyResolve.Start();
                if (useNewThread)
                {
                    _runCodeThread = new Thread(new ThreadStart(() => _Run(runMethod, initMethod, endMethod)));
                    _runCodeThread.CurrentCulture = FormatInfo.CurrentFormat.CurrentCulture;
                    _runCodeThread.SetApartmentState(ApartmentState.STA);
                    _runCodeThread.Start();
                }
                else
                {
                    Trace.WriteLine("execute on main thread");
                    _Run(runMethod, initMethod, endMethod);
                }

                bOk = true;
            }
            catch
            {
                bError = true;
                throw;
            }
            finally
            {
                if (!bOk && EndRun != null)
                {
                    EndRun(bError);
                }
            }
        }