Index: /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs
===================================================================
--- /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs	(revision 13276)
+++ /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs	(revision 13277)
@@ -30,13 +30,8 @@
   [StorableClass]
   public sealed class MultiObjectiveOptimizationSupportScript : OptimizationSupportScript<IMultiObjectiveOptimizationSupport>, IMultiObjectiveOptimizationSupport {
-
-    protected override string CodeTemplate {
-      get { return Templates.CompiledMultiObjectiveOptimizationSupport; }
-    }
-
     [StorableConstructor]
     private MultiObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { }
     private MultiObjectiveOptimizationSupportScript(MultiObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { }
-    public MultiObjectiveOptimizationSupportScript() : base() { }
+    public MultiObjectiveOptimizationSupportScript() : base(Templates.CompiledMultiObjectiveOptimizationSupport) { }
 
     public override IDeepCloneable Clone(Cloner cloner) {
Index: /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScript.cs
===================================================================
--- /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScript.cs	(revision 13276)
+++ /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScript.cs	(revision 13277)
@@ -46,4 +46,9 @@
     protected OptimizationSupportScript()
       : base() {
+      variableStore = new VariableStore();
+    }
+
+    protected OptimizationSupportScript(string code)
+      : base(code) {
       variableStore = new VariableStore();
     }
Index: /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs
===================================================================
--- /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs	(revision 13276)
+++ /stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs	(revision 13277)
@@ -31,13 +31,8 @@
   [StorableClass]
   public sealed class SingleObjectiveOptimizationSupportScript : OptimizationSupportScript<ISingleObjectiveOptimizationSupport>, ISingleObjectiveOptimizationSupport {
-
-    protected override string CodeTemplate {
-      get { return Templates.CompiledSingleObjectiveOptimizationSupport; }
-    }
-
     [StorableConstructor]
     private SingleObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { }
     private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { }
-    public SingleObjectiveOptimizationSupportScript() : base() { }
+    public SingleObjectiveOptimizationSupportScript() : base(Templates.CompiledSingleObjectiveOptimizationSupport) { }
 
     public override IDeepCloneable Clone(Cloner cloner) {
Index: /stable/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs
===================================================================
--- /stable/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs	(revision 13276)
+++ /stable/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs	(revision 13277)
@@ -31,8 +31,4 @@
     public string Filename { get; set; }
 
-    protected override string CodeTemplate {
-      get { return ScriptTemplates.CompiledMultiObjectiveProblemDefinition; }
-    }
-
     private new IMultiObjectiveProblemDefinition CompiledProblemDefinition {
       get { return (IMultiObjectiveProblemDefinition)base.CompiledProblemDefinition; }
@@ -41,10 +37,6 @@
     [StorableConstructor]
     private MultiObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
-    private MultiObjectiveProblemDefinitionScript(MultiObjectiveProblemDefinitionScript original, Cloner cloner)
-      : base(original, cloner) { }
-
-    public MultiObjectiveProblemDefinitionScript() {
-      Code = CodeTemplate;
-    }
+    private MultiObjectiveProblemDefinitionScript(MultiObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
+    public MultiObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledMultiObjectiveProblemDefinition) { }
 
     public override IDeepCloneable Clone(Cloner cloner) {
Index: /stable/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs
===================================================================
--- /stable/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs	(revision 13276)
+++ /stable/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs	(revision 13277)
@@ -53,4 +53,8 @@
     protected ProblemDefinitionScript()
       : base() {
+      variableStore = new VariableStore();
+    }
+    protected ProblemDefinitionScript(string code)
+      : base(code) {
       variableStore = new VariableStore();
     }
Index: /stable/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
===================================================================
--- /stable/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs	(revision 13276)
+++ /stable/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs	(revision 13277)
@@ -32,8 +32,4 @@
     public string Filename { get; set; }
 
-    protected override string CodeTemplate {
-      get { return ScriptTemplates.CompiledSingleObjectiveProblemDefinition; }
-    }
-
     private new ISingleObjectiveProblemDefinition CompiledProblemDefinition {
       get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; }
@@ -43,8 +39,5 @@
     private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
-    public SingleObjectiveProblemDefinitionScript()
-      : base() {
-      Code = CodeTemplate;
-    }
+    public SingleObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledSingleObjectiveProblemDefinition) { }
 
     public override IDeepCloneable Clone(Cloner cloner) {
Index: /stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.Designer.cs
===================================================================
--- /stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.Designer.cs	(revision 13276)
+++ /stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.Designer.cs	(revision 13277)
@@ -20,5 +20,4 @@
 #endregion
 
-using System.Windows.Forms;
 
 namespace HeuristicLab.Scripting.Views {
@@ -47,9 +46,14 @@
     /// </summary>
     private void InitializeComponent() {
-      this.components = new System.ComponentModel.Container();
-      this.startStopButton = new System.Windows.Forms.Button();
       this.splitContainer2 = new System.Windows.Forms.SplitContainer();
       this.variableStoreView = new HeuristicLab.Scripting.Views.VariableStoreView();
       this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
+      this.infoTabControl.SuspendLayout();
+      this.outputTabPage.SuspendLayout();
+      this.errorListTabPage.SuspendLayout();
+      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
+      this.splitContainer1.Panel1.SuspendLayout();
+      this.splitContainer1.Panel2.SuspendLayout();
+      this.splitContainer1.SuspendLayout();
       ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
       ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
@@ -59,26 +63,23 @@
       this.SuspendLayout();
       // 
-      // nameTextBox
+      // executionTimeLabel
       // 
-      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
-      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
-      this.nameTextBox.Location = new System.Drawing.Point(60, 0);
-      this.nameTextBox.Size = new System.Drawing.Size(750, 20);
+      this.executionTimeLabel.Location = new System.Drawing.Point(409, 3);
       // 
-      // infoLabel
+      // executionTimeTextBox
       // 
-      this.infoLabel.Location = new System.Drawing.Point(816, 4);
+      this.executionTimeTextBox.Location = new System.Drawing.Point(498, 0);
       // 
-      // startStopButton
+      // infoTabControl
       // 
-      this.startStopButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;
-      this.startStopButton.Location = new System.Drawing.Point(36, 26);
-      this.startStopButton.Name = "startStopButton";
-      this.startStopButton.Size = new System.Drawing.Size(24, 24);
-      this.startStopButton.TabIndex = 1;
-      this.startStopButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
-      this.toolTip.SetToolTip(this.startStopButton, "Run (F5)");
-      this.startStopButton.UseVisualStyleBackColor = true;
-      this.startStopButton.Click += new System.EventHandler(this.StartStopButtonOnClick);
+      this.infoTabControl.Size = new System.Drawing.Size(637, 110);
+      // 
+      // splitContainer1
+      // 
+      this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
+      this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
+      this.splitContainer1.Location = new System.Drawing.Point(0, 0);
+      this.splitContainer1.Size = new System.Drawing.Size(637, 543);
+      this.splitContainer1.SplitterDistance = 427;
       // 
       // splitContainer2
@@ -101,9 +102,4 @@
       this.splitContainer2.SplitterDistance = 637;
       this.splitContainer2.TabIndex = 7;
-      //
-      // splitContainer1
-      //
-      this.splitContainer1.Location = new System.Drawing.Point(0, 0);
-      this.splitContainer1.Dock = DockStyle.Fill;
       // 
       // variableStoreView
@@ -132,11 +128,11 @@
       this.viewHost.ViewType = null;
       // 
-      // ScriptView
+      // CSharpScriptView
       // 
       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
       this.Controls.Add(this.splitContainer2);
-      this.Controls.Add(this.startStopButton);
-      this.Name = "ScriptView";
-      this.Size = new System.Drawing.Size(835, 602);
+      this.Name = "CSharpScriptView";
+      this.Controls.SetChildIndex(this.infoTextLabel, 0);
+      this.Controls.SetChildIndex(this.compileButton, 0);
       this.Controls.SetChildIndex(this.startStopButton, 0);
       this.Controls.SetChildIndex(this.splitContainer2, 0);
@@ -144,4 +140,14 @@
       this.Controls.SetChildIndex(this.nameTextBox, 0);
       this.Controls.SetChildIndex(this.infoLabel, 0);
+      this.infoTabControl.ResumeLayout(false);
+      this.outputTabPage.ResumeLayout(false);
+      this.outputTabPage.PerformLayout();
+      this.errorListTabPage.ResumeLayout(false);
+      this.splitContainer1.Panel1.ResumeLayout(false);
+      this.splitContainer1.Panel2.ResumeLayout(false);
+      this.splitContainer1.Panel2.PerformLayout();
+      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
+      this.splitContainer1.ResumeLayout(false);
+      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
       this.splitContainer2.Panel1.ResumeLayout(false);
       this.splitContainer2.Panel2.ResumeLayout(false);
@@ -155,5 +161,4 @@
     #endregion
 
-    protected System.Windows.Forms.Button startStopButton;
     protected System.Windows.Forms.SplitContainer splitContainer2;
     protected MainForm.WindowsForms.ViewHost viewHost;
Index: /stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs
===================================================================
--- /stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs	(revision 13276)
+++ /stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs	(revision 13277)
@@ -21,9 +21,6 @@
 
 using System;
-using System.Drawing;
-using System.Threading;
 using System.Windows.Forms;
 using HeuristicLab.Common;
-using HeuristicLab.Common.Resources;
 using HeuristicLab.MainForm;
 
@@ -32,11 +29,5 @@
   [View("C# Script View")]
   [Content(typeof(CSharpScript), true)]
-  public partial class CSharpScriptView : ScriptView {
-    private const string ScriptExecutionStartedMessage = "Script execution started";
-    private const string ScriptExecutionCanceledMessage = "Script execution canceled";
-    private const string ScriptExecutionSuccessfulMessage = "Script execution successful";
-    private const string ScriptExecutionFailedMessage = "Script execution failed";
-
-    protected bool Running { get; set; }
+  public partial class CSharpScriptView : ExecutableScriptView {
 
     public new CSharpScript Content {
@@ -51,12 +42,8 @@
     protected override void RegisterContentEvents() {
       base.RegisterContentEvents();
-      Content.ScriptExecutionStarted += ContentOnScriptExecutionStarted;
-      Content.ScriptExecutionFinished += ContentOnScriptExecutionFinished;
       Content.ConsoleOutputChanged += ContentOnConsoleOutputChanged;
     }
 
     protected override void DeregisterContentEvents() {
-      Content.ScriptExecutionStarted -= ContentOnScriptExecutionStarted;
-      Content.ScriptExecutionFinished -= ContentOnScriptExecutionFinished;
       Content.ConsoleOutputChanged -= ContentOnConsoleOutputChanged;
       base.DeregisterContentEvents();
@@ -64,39 +51,4 @@
 
     #region Content event handlers
-    protected virtual void ContentOnScriptExecutionStarted(object sender, EventArgs e) {
-      if (InvokeRequired)
-        Invoke((Action<object, EventArgs>)ContentOnScriptExecutionStarted, sender, e);
-      else {
-        Locked = true;
-        ReadOnly = true;
-        startStopButton.Image = VSImageLibrary.Stop;
-        toolTip.SetToolTip(startStopButton, "Stop (Shift+F5)");
-        UpdateInfoTextLabel(ScriptExecutionStartedMessage, SystemColors.ControlText);
-        infoTabControl.SelectedTab = outputTabPage;
-      }
-    }
-    protected virtual void ContentOnScriptExecutionFinished(object sender, EventArgs<Exception> e) {
-      if (InvokeRequired)
-        Invoke((Action<object, EventArgs<Exception>>)ContentOnScriptExecutionFinished, sender, e);
-      else {
-        Locked = false;
-        ReadOnly = false;
-        startStopButton.Image = VSImageLibrary.Play;
-        toolTip.SetToolTip(startStopButton, "Run (F5)");
-
-        var ex = e.Value;
-        if (ex == null) {
-          UpdateInfoTextLabel(ScriptExecutionSuccessfulMessage, Color.DarkGreen);
-        } else if (ex is ThreadAbortException) {
-          // the execution was canceled by the user
-          UpdateInfoTextLabel(ScriptExecutionCanceledMessage, Color.DarkOrange);
-        } else {
-          UpdateInfoTextLabel(ScriptExecutionFailedMessage, Color.DarkRed);
-          PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);
-        }
-
-        Running = false;
-      }
-    }
     protected virtual void ContentOnConsoleOutputChanged(object sender, EventArgs<string> e) {
       if (InvokeRequired)
@@ -116,43 +68,4 @@
       }
     }
-
-    protected override void SetEnabledStateOfControls() {
-      base.SetEnabledStateOfControls();
-      startStopButton.Enabled = Content != null && (!Locked || Running);
-    }
-
-    protected virtual void StartStopButtonOnClick(object sender, EventArgs e) {
-      if (Running) {
-        Content.Kill();
-      } else
-        if (Compile()) {
-          outputTextBox.Clear();
-          Running = true;
-          Content.ExecuteAsync();
-        }
-    }
-
-    #region global HotKeys
-    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
-      switch (keyData) {
-        case Keys.F5:
-          if (Content != null && !Locked && !Running) {
-            if (Compile()) {
-              outputTextBox.Clear();
-              Content.ExecuteAsync();
-              Running = true;
-            }
-          }
-          return true;
-        case Keys.F5 | Keys.Shift:
-          if (Running) Content.Kill();
-          return true;
-        case Keys.F6:
-          if (!Running) base.ProcessCmdKey(ref msg, keyData);
-          return true;
-      }
-      return base.ProcessCmdKey(ref msg, keyData);
-    }
-    #endregion
   }
 }
Index: /stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.Designer.cs
===================================================================
--- /stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.Designer.cs	(revision 13277)
+++ /stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.Designer.cs	(revision 13277)
@@ -0,0 +1,119 @@
+﻿namespace HeuristicLab.Scripting.Views {
+  partial class ExecutableScriptView {
+    /// <summary> 
+    /// Required designer variable.
+    /// </summary>
+    private System.ComponentModel.IContainer components = null;
+
+    /// <summary> 
+    /// Clean up any resources being used.
+    /// </summary>
+    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+    protected override void Dispose(bool disposing) {
+      if (disposing && (components != null)) {
+        components.Dispose();
+      }
+      base.Dispose(disposing);
+    }
+
+    #region Component Designer generated code
+
+    /// <summary> 
+    /// Required method for Designer support - do not modify 
+    /// the contents of this method with the code editor.
+    /// </summary>
+    private void InitializeComponent() {
+      this.startStopButton = new System.Windows.Forms.Button();
+      this.executionTimeLabel = new System.Windows.Forms.Label();
+      this.executionTimeTextBox = new System.Windows.Forms.TextBox();
+      this.infoTabControl.SuspendLayout();
+      this.outputTabPage.SuspendLayout();
+      this.errorListTabPage.SuspendLayout();
+      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
+      this.splitContainer1.Panel1.SuspendLayout();
+      this.splitContainer1.Panel2.SuspendLayout();
+      this.splitContainer1.SuspendLayout();
+      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
+      this.SuspendLayout();
+      // 
+      // splitContainer1
+      // 
+      // 
+      // splitContainer1.Panel2
+      // 
+      this.splitContainer1.Panel2.Controls.Add(this.executionTimeLabel);
+      this.splitContainer1.Panel2.Controls.Add(this.executionTimeTextBox);
+      this.splitContainer1.Panel2.Controls.SetChildIndex(this.executionTimeTextBox, 0);
+      this.splitContainer1.Panel2.Controls.SetChildIndex(this.executionTimeLabel, 0);
+      // 
+      // nameTextBox
+      // 
+      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
+      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
+      // 
+      // startStopButton
+      // 
+      this.startStopButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;
+      this.startStopButton.Location = new System.Drawing.Point(36, 26);
+      this.startStopButton.Name = "startStopButton";
+      this.startStopButton.Size = new System.Drawing.Size(24, 24);
+      this.startStopButton.TabIndex = 10;
+      this.startStopButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
+      this.toolTip.SetToolTip(this.startStopButton, "Run (F5)");
+      this.startStopButton.UseVisualStyleBackColor = true;
+      this.startStopButton.Click += new System.EventHandler(this.startStopButton_Click);
+      // 
+      // executionTimeLabel
+      // 
+      this.executionTimeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+      this.executionTimeLabel.AutoSize = true;
+      this.executionTimeLabel.Location = new System.Drawing.Point(604, 3);
+      this.executionTimeLabel.Name = "executionTimeLabel";
+      this.executionTimeLabel.Size = new System.Drawing.Size(83, 13);
+      this.executionTimeLabel.TabIndex = 18;
+      this.executionTimeLabel.Text = "&Execution Time:";
+      // 
+      // executionTimeTextBox
+      // 
+      this.executionTimeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+      this.executionTimeTextBox.Location = new System.Drawing.Point(693, 0);
+      this.executionTimeTextBox.Name = "executionTimeTextBox";
+      this.executionTimeTextBox.ReadOnly = true;
+      this.executionTimeTextBox.Size = new System.Drawing.Size(137, 20);
+      this.executionTimeTextBox.TabIndex = 19;
+      // 
+      // ExecutableScriptView
+      // 
+      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+      this.Controls.Add(this.startStopButton);
+      this.Name = "ExecutableScriptView";
+      this.Controls.SetChildIndex(this.infoTextLabel, 0);
+      this.Controls.SetChildIndex(this.compileButton, 0);
+      this.Controls.SetChildIndex(this.splitContainer1, 0);
+      this.Controls.SetChildIndex(this.nameLabel, 0);
+      this.Controls.SetChildIndex(this.nameTextBox, 0);
+      this.Controls.SetChildIndex(this.infoLabel, 0);
+      this.Controls.SetChildIndex(this.startStopButton, 0);
+      this.infoTabControl.ResumeLayout(false);
+      this.outputTabPage.ResumeLayout(false);
+      this.outputTabPage.PerformLayout();
+      this.errorListTabPage.ResumeLayout(false);
+      this.splitContainer1.Panel1.ResumeLayout(false);
+      this.splitContainer1.Panel2.ResumeLayout(false);
+      this.splitContainer1.Panel2.PerformLayout();
+      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
+      this.splitContainer1.ResumeLayout(false);
+      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
+      this.ResumeLayout(false);
+      this.PerformLayout();
+
+    }
+
+    #endregion
+
+    protected System.Windows.Forms.Button startStopButton;
+    protected System.Windows.Forms.Label executionTimeLabel;
+    protected System.Windows.Forms.TextBox executionTimeTextBox;
+  }
+}
Index: /stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.cs
===================================================================
--- /stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.cs	(revision 13277)
+++ /stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.cs	(revision 13277)
@@ -0,0 +1,152 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Drawing;
+using System.Threading;
+using System.Windows.Forms;
+using HeuristicLab.Common;
+using HeuristicLab.Common.Resources;
+using HeuristicLab.MainForm;
+
+namespace HeuristicLab.Scripting.Views {
+  [View("Executable Script View")]
+  [Content(typeof(ExecutableScript), true)]
+  public partial class ExecutableScriptView : ScriptView {
+    private const string ScriptExecutionStartedMessage = "Script execution started";
+    private const string ScriptExecutionCanceledMessage = "Script execution canceled";
+    private const string ScriptExecutionSuccessfulMessage = "Script execution successful";
+    private const string ScriptExecutionFailedMessage = "Script execution failed";
+
+    protected bool Running {
+      get { return Content.Running; }
+    }
+
+    public new ExecutableScript Content {
+      get { return (ExecutableScript)base.Content; }
+      set { base.Content = value; }
+    }
+
+    public ExecutableScriptView() {
+      InitializeComponent();
+    }
+
+    protected override void RegisterContentEvents() {
+      base.RegisterContentEvents();
+      Content.ScriptExecutionStarted += ContentOnScriptExecutionStarted;
+      Content.ScriptExecutionFinished += ContentOnScriptExecutionFinished;
+      Content.ExecutionTimeChanged += ContentOnExecutionTimeChanged;
+    }
+
+    protected override void DeregisterContentEvents() {
+      Content.ScriptExecutionStarted -= ContentOnScriptExecutionStarted;
+      Content.ScriptExecutionFinished -= ContentOnScriptExecutionFinished;
+      Content.ExecutionTimeChanged -= ContentOnExecutionTimeChanged;
+      base.DeregisterContentEvents();
+    }
+
+    #region Event Handlers
+    protected virtual void ContentOnScriptExecutionStarted(object sender, EventArgs e) {
+      if (InvokeRequired)
+        Invoke((Action<object, EventArgs>)ContentOnScriptExecutionStarted, sender, e);
+      else {
+        Locked = true;
+        ReadOnly = true;
+        startStopButton.Image = VSImageLibrary.Stop;
+        toolTip.SetToolTip(startStopButton, "Stop (Shift+F5)");
+        UpdateInfoTextLabel(ScriptExecutionStartedMessage, SystemColors.ControlText);
+        infoTabControl.SelectedTab = outputTabPage;
+      }
+    }
+    protected virtual void ContentOnScriptExecutionFinished(object sender, EventArgs<Exception> e) {
+      if (InvokeRequired)
+        Invoke((Action<object, EventArgs<Exception>>)ContentOnScriptExecutionFinished, sender, e);
+      else {
+        Locked = false;
+        ReadOnly = false;
+        startStopButton.Image = VSImageLibrary.Play;
+        toolTip.SetToolTip(startStopButton, "Run (F5)");
+
+        var ex = e.Value;
+        if (ex == null) {
+          UpdateInfoTextLabel(ScriptExecutionSuccessfulMessage, Color.DarkGreen);
+        } else if (ex is ThreadAbortException) {
+          // the execution was canceled by the user
+          UpdateInfoTextLabel(ScriptExecutionCanceledMessage, Color.DarkOrange);
+        } else {
+          UpdateInfoTextLabel(ScriptExecutionFailedMessage, Color.DarkRed);
+          PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);
+        }
+      }
+    }
+    protected virtual void ContentOnExecutionTimeChanged(object sender, EventArgs eventArgs) {
+      if (InvokeRequired)
+        Invoke((Action<object, EventArgs>)ContentOnExecutionTimeChanged, sender, eventArgs);
+      else {
+        executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
+      }
+    }
+    #endregion
+
+    protected override void OnContentChanged() {
+      base.OnContentChanged();
+      if (Content == null) {
+        executionTimeTextBox.Text = "-";
+      } else {
+        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
+      }
+    }
+
+    protected override void SetEnabledStateOfControls() {
+      base.SetEnabledStateOfControls();
+      startStopButton.Enabled = Content != null && (!Locked || Running);
+    }
+
+    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
+      switch (keyData) {
+        case Keys.F5:
+          if (Content != null && !Locked && !Running) {
+            if (Compile()) {
+              outputTextBox.Clear();
+              Content.ExecuteAsync();
+            }
+          }
+          return true;
+        case Keys.F5 | Keys.Shift:
+          if (Running) Content.Kill();
+          return true;
+        case Keys.F6:
+          if (!Running) base.ProcessCmdKey(ref msg, keyData);
+          return true;
+      }
+      return base.ProcessCmdKey(ref msg, keyData);
+    }
+
+    private void startStopButton_Click(object sender, EventArgs e) {
+      if (Running) {
+        Content.Kill();
+      } else if (Compile()) {
+        outputTextBox.Clear();
+        Content.ExecuteAsync();
+      }
+    }
+  }
+}
Index: /stable/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj
===================================================================
--- /stable/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj	(revision 13276)
+++ /stable/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj	(revision 13277)
@@ -97,4 +97,10 @@
     <Compile Include="CSharpScriptView.Designer.cs">
       <DependentUpon>CSharpScriptView.cs</DependentUpon>
+    </Compile>
+    <Compile Include="ExecutableScriptView.cs">
+      <SubType>UserControl</SubType>
+    </Compile>
+    <Compile Include="ExecutableScriptView.Designer.cs">
+      <DependentUpon>ExecutableScriptView.cs</DependentUpon>
     </Compile>
     <Compile Include="ScriptView.cs">
Index: /stable/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs
===================================================================
--- /stable/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs	(revision 13276)
+++ /stable/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs	(revision 13277)
@@ -118,11 +118,13 @@
       // infoTabControl
       // 
+      this.infoTabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.infoTabControl.Controls.Add(this.outputTabPage);
       this.infoTabControl.Controls.Add(this.errorListTabPage);
-      this.infoTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
-      this.infoTabControl.Location = new System.Drawing.Point(0, 0);
+      this.infoTabControl.Location = new System.Drawing.Point(0, 2);
       this.infoTabControl.Name = "infoTabControl";
       this.infoTabControl.SelectedIndex = 0;
-      this.infoTabControl.Size = new System.Drawing.Size(832, 112);
+      this.infoTabControl.Size = new System.Drawing.Size(832, 110);
       this.infoTabControl.TabIndex = 1;
       // 
@@ -133,5 +135,5 @@
       this.outputTabPage.Name = "outputTabPage";
       this.outputTabPage.Padding = new System.Windows.Forms.Padding(3);
-      this.outputTabPage.Size = new System.Drawing.Size(824, 86);
+      this.outputTabPage.Size = new System.Drawing.Size(824, 84);
       this.outputTabPage.TabIndex = 1;
       this.outputTabPage.Text = "Output";
@@ -147,5 +149,5 @@
       this.outputTextBox.ReadOnly = true;
       this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
-      this.outputTextBox.Size = new System.Drawing.Size(818, 80);
+      this.outputTextBox.Size = new System.Drawing.Size(818, 78);
       this.outputTextBox.TabIndex = 0;
       this.outputTextBox.WordWrap = false;
Index: /stable/HeuristicLab.Scripting/3.3/ExecutableScript.cs
===================================================================
--- /stable/HeuristicLab.Scripting/3.3/ExecutableScript.cs	(revision 13277)
+++ /stable/HeuristicLab.Scripting/3.3/ExecutableScript.cs	(revision 13277)
@@ -0,0 +1,139 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Threading;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Scripting {
+  [Item("Executable Script", "An executable script.")]
+  [StorableClass]
+  public abstract class ExecutableScript : Script {
+    private Thread scriptThread;
+    private DateTime lastUpdateTime;
+
+    [Storable]
+    private TimeSpan executionTime;
+    public TimeSpan ExecutionTime {
+      get { return executionTime; }
+      protected set {
+        executionTime = value;
+        OnExecutionTimeChanged();
+      }
+    }
+
+    public bool Running { get; protected set; }
+
+    #region Construction & Cloning
+    [StorableConstructor]
+    protected ExecutableScript(bool deserializing) : base(deserializing) { }
+    protected ExecutableScript(ExecutableScript original, Cloner cloner)
+      : base(original, cloner) {
+      executionTime = original.executionTime;
+    }
+    protected ExecutableScript()
+      : base() {
+      executionTime = TimeSpan.Zero;
+    }
+    protected ExecutableScript(string code)
+      : base(code) {
+      executionTime = TimeSpan.Zero;
+    }
+    #endregion
+
+    #region Execution
+    protected abstract void ExecuteCode();
+
+    public virtual void Execute() {
+      if (Running)
+        throw new InvalidOperationException("Script is already running");
+
+      ExecutionTime = TimeSpan.Zero;
+      Exception ex = null;
+      var timer = new System.Timers.Timer(250) { AutoReset = true };
+      timer.Elapsed += timer_Elapsed;
+      try {
+        Running = true;
+        OnScriptExecutionStarted();
+        lastUpdateTime = DateTime.UtcNow;
+        timer.Start();
+        ExecuteCode();
+      } catch (Exception e) {
+        ex = e;
+      } finally {
+        timer.Elapsed -= timer_Elapsed;
+        timer.Stop();
+        timer.Dispose();
+        ExecutionTime += DateTime.UtcNow - lastUpdateTime;
+        Running = false;
+        OnScriptExecutionFinished(ex);
+      }
+    }
+
+    public virtual void ExecuteAsync() {
+      scriptThread = new Thread(() => {
+        try {
+          Execute();
+        } finally {
+          scriptThread = null;
+        }
+      });
+      scriptThread.SetApartmentState(ApartmentState.STA);
+      scriptThread.Start();
+    }
+
+    public virtual void Kill() {
+      if (!Running) return;
+
+      scriptThread.Abort();
+    }
+    #endregion
+
+    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
+      var timer = (System.Timers.Timer)sender;
+      timer.Enabled = false;
+      DateTime now = DateTime.UtcNow;
+      ExecutionTime += now - lastUpdateTime;
+      lastUpdateTime = now;
+      timer.Enabled = true;
+    }
+
+    public event EventHandler ScriptExecutionStarted;
+    protected virtual void OnScriptExecutionStarted() {
+      var handler = ScriptExecutionStarted;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+
+    public event EventHandler<EventArgs<Exception>> ScriptExecutionFinished;
+    protected virtual void OnScriptExecutionFinished(Exception e) {
+      var handler = ScriptExecutionFinished;
+      if (handler != null) handler(this, new EventArgs<Exception>(e));
+    }
+
+    public event EventHandler ExecutionTimeChanged;
+    protected virtual void OnExecutionTimeChanged() {
+      var handler = ExecutionTimeChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+  }
+}
Index: /stable/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj
===================================================================
--- /stable/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj	(revision 13276)
+++ /stable/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj	(revision 13277)
@@ -92,4 +92,5 @@
   <ItemGroup>
     <Compile Include="CompilationException.cs" />
+    <Compile Include="ExecutableScript.cs" />
     <Compile Include="Scripts\CSharp\CSharpScript.cs" />
     <Compile Include="Scripts\Templates\CSharpScriptTemplate.cs" />
Index: /stable/HeuristicLab.Scripting/3.3/Script.cs
===================================================================
--- /stable/HeuristicLab.Scripting/3.3/Script.cs	(revision 13276)
+++ /stable/HeuristicLab.Scripting/3.3/Script.cs	(revision 13277)
@@ -37,9 +37,5 @@
 namespace HeuristicLab.Scripting {
   [StorableClass]
-  public class Script : NamedItem, IProgrammableItem {
-    protected virtual string CodeTemplate {
-      get { return string.Empty; }
-    }
-
+  public abstract class Script : NamedItem, IProgrammableItem {
     #region Fields & Properties
     public static new Image StaticItemImage {
@@ -77,28 +73,14 @@
         compileErrors = new CompilerErrorCollection(original.compileErrors);
     }
-    public Script()
+    protected Script()
       : base("Script", "An empty script.") {
-      code = CodeTemplate;
     }
-    public Script(string code)
+    protected Script(string code)
       : this() {
       this.code = code;
-    }
-
-    public override IDeepCloneable Clone(Cloner cloner) {
-      return new Script(this, cloner);
     }
     #endregion
 
     #region Compilation
-    protected virtual CSharpCodeProvider CodeProvider {
-      get {
-        return new CSharpCodeProvider(
-          new Dictionary<string, string> {
-                {"CompilerVersion", "v4.0"}, // support C# 4.0 syntax
-              });
-      }
-    }
-
     protected virtual CompilerResults DoCompile() {
       var parameters = new CompilerParameters {
@@ -114,5 +96,10 @@
         .ToArray());
 
-      return CodeProvider.CompileAssemblyFromSource(parameters, code);
+      var codeProvider = new CSharpCodeProvider(
+        new Dictionary<string, string> {
+          { "CompilerVersion", "v4.0"} // support C# 4.0 syntax
+        });
+
+      return codeProvider.CompileAssemblyFromSource(parameters, code);
     }
 
Index: /stable/HeuristicLab.Scripting/3.3/Scripts/CSharp/CSharpScript.cs
===================================================================
--- /stable/HeuristicLab.Scripting/3.3/Scripts/CSharp/CSharpScript.cs	(revision 13276)
+++ /stable/HeuristicLab.Scripting/3.3/Scripts/CSharp/CSharpScript.cs	(revision 13277)
@@ -23,5 +23,4 @@
 using System.Linq;
 using System.Reflection;
-using System.Threading;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -32,10 +31,5 @@
   [Creatable(CreatableAttribute.Categories.Scripts, Priority = 100)]
   [StorableClass]
-  public class CSharpScript : Script, IStorableContent {
-    #region Constants
-    protected const string ExecuteMethodName = "Execute";
-    protected override string CodeTemplate { get { return ScriptTemplates.CSharpScriptTemplate; } }
-    #endregion
-
+  public class CSharpScript : ExecutableScript, IStorableContent {
     #region Fields & Properties
     private CSharpScriptBase compiledScript;
@@ -50,5 +44,5 @@
     #endregion
 
-    #region Construction & Initialization
+    #region Construction & Cloning
     [StorableConstructor]
     protected CSharpScript(bool deserializing) : base(deserializing) { }
@@ -57,7 +51,7 @@
       variableStore = cloner.Clone(original.variableStore);
     }
-    public CSharpScript() {
+    public CSharpScript()
+      : base(ScriptTemplates.CSharpScriptTemplate) {
       variableStore = new VariableStore();
-      Code = CodeTemplate;
     }
     public CSharpScript(string code)
@@ -82,5 +76,4 @@
 
     #region Compilation
-
     public override Assembly Compile() {
       DeregisterScriptEvents();
@@ -94,44 +87,12 @@
     #endregion
 
-    private Thread scriptThread;
-    public virtual void ExecuteAsync() {
+    protected override void ExecuteCode() {
       if (compiledScript == null) return;
-      scriptThread = new Thread(() => {
-        Exception ex = null;
-        try {
-          OnScriptExecutionStarted();
-          compiledScript.Execute(VariableStore);
-        }
-        catch (Exception e) {
-          ex = e;
-        }
-        finally {
-          scriptThread = null;
-          OnScriptExecutionFinished(ex);
-        }
-      });
-      scriptThread.SetApartmentState(ApartmentState.STA);
-      scriptThread.Start();
-    }
 
-    public virtual void Kill() {
-      if (scriptThread == null) return;
-      scriptThread.Abort();
+      compiledScript.Execute(VariableStore);
     }
 
     protected virtual void CompiledScriptOnConsoleOutputChanged(object sender, EventArgs<string> e) {
       OnConsoleOutputChanged(e.Value);
-    }
-
-    public event EventHandler ScriptExecutionStarted;
-    protected virtual void OnScriptExecutionStarted() {
-      var handler = ScriptExecutionStarted;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-
-    public event EventHandler<EventArgs<Exception>> ScriptExecutionFinished;
-    protected virtual void OnScriptExecutionFinished(Exception e) {
-      var handler = ScriptExecutionFinished;
-      if (handler != null) handler(this, new EventArgs<Exception>(e));
     }
 
