'cAlgo.API.Application' does not contain a definition for 'Run' and no extension method 'Run' - Winform

Created at 18 Nov 2019, 18:19
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
JO

johncarlodelacruz

Joined 31.10.2019

'cAlgo.API.Application' does not contain a definition for 'Run' and no extension method 'Run' - Winform
18 Nov 2019, 18:19


Hi,

After I update CTrader to 3.6, I got an error on my code that is running a winform.

It says that  'cAlgo.API.Application' does not contain a definition for 'Run' and no extension method 'Run'.

Am I missing something on the update?

 

using System;
using System.Threading;
using System.Windows.Forms;
using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class Winform : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private Thread thread;
        private Form form;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.ComboBox comboBox1;

        [STAThread()]
        protected override void OnStart()
        {
            thread = new Thread(new ThreadStart(WindowsApp));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            while (thread.IsAlive)
                System.Windows.Forms.Application.DoEvents();
        }

        protected override void OnTick()
        {
            Print("OnTick test");
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }

        [STAThread()]
        private void WindowsApp()
        {
            form = new Form();
            InitializeComponent();
            form.AutoScaleDimensions = new System.Drawing.SizeF(8f, 16f);
            form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            form.ClientSize = new System.Drawing.Size(443, 633);
            form.Controls.Add(this.groupBox1);
            form.Name = "Form1";
            form.Text = "Test";
            form.TopMost = true;
            form.ResumeLayout(false);
            form.PerformLayout();
            Application.Run(form);
        }
        //
        // PButton "TEST"
        //        
        private void button1_Click(object sender, EventArgs e)
        {
            Print("Button test");

            int comboBox1Value = Convert.ToInt32(comboBox1.SelectedItem);
            Print("ComboBox1 = " + comboBox1Value);
        }

        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.button1 = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.comboBox1);
            this.groupBox1.Controls.Add(this.button1);
            this.groupBox1.Location = new System.Drawing.Point(0, 0);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(444, 225);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "groupBox1";
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Items.AddRange(new object[] 
            {
                1,
                2,
                3,
                5,
                10
            });
            this.comboBox1.Location = new System.Drawing.Point(15, 71);
            this.comboBox1.Name = "comboBox10";
            this.comboBox1.Size = new System.Drawing.Size(61, 24);
            this.comboBox1.TabIndex = 4;
            // 
            // button1 test
            // 
            this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
            this.button1.Cursor = System.Windows.Forms.Cursors.Hand;
            this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.button1.Location = new System.Drawing.Point(295, 21);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(122, 40);
            this.button1.TabIndex = 2;
            this.button1.Text = "TEST";
            this.button1.UseVisualStyleBackColor = false;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
        }
    }
}

It's on line 55.

 

Thank you.


@johncarlodelacruz
Replies

PanagiotisCharalampous
19 Nov 2019, 08:25

Hi johncarlodelacruz,

You need to replace line 55 with the following

 System.Windows.Forms.Application.Run(form);

Best Regards,

Panagiotis


@PanagiotisCharalampous