How to invoke a form inside another form taskHow do I enumerate an enum in C#?Should 'using' directives be inside or outside the namespace?How do I update the GUI from another thread?C# Opening a Form, then closing it from another methodHow to transfer text and numeric updown value to a listbox in another form?C# How use sign from another window?Accessing string from another FormFilename pattern not working in OpenFileDialogHide and restore the GUI Mutiple forms in c#In C# how to open third form inside first form when i click a button of the second form

Why does the UK have more political parties than the US?

Can a helicopter mask itself from Radar?

Creating Fictional Slavic Place Names

'chmod' would set file permission to 000 no matter what permission I try to set

How do I get a list of only the files (not the directories) from a package?

What caused the tendency for conservatives to not support climate change regulations?

Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?

How to read a field in the variant template?

Is it possible to kill all life on Earth?

Asking bank to reduce APR instead of increasing credit limit

Is a hash a zero-knowledge proof?

The original word for a wild boar

Looking after a wayward brother in mother's will

The term for the person/group a political party aligns themselves with to appear concerned about the general public

Did airlines fly their aircraft slower in response to oil prices in the 1970s?

Future enhancements for the finite element method

How to detach yourself from a character you're going to kill?

How can I offer a test ride while selling a bike?

Order by does not work as I expect

Rotated Position of Integers

How crucial is a waifu game storyline?

Is EUM the only possible translation for HIM as direct object?

How to install HarfTeX on TeXLive?

Why were the Night's Watch required to be celibate?



How to invoke a form inside another form task


How do I enumerate an enum in C#?Should 'using' directives be inside or outside the namespace?How do I update the GUI from another thread?C# Opening a Form, then closing it from another methodHow to transfer text and numeric updown value to a listbox in another form?C# How use sign from another window?Accessing string from another FormFilename pattern not working in OpenFileDialogHide and restore the GUI Mutiple forms in c#In C# how to open third form inside first form when i click a button of the second form






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















In my Windows Form application I have created 2 Forms. In form 1 when I click button1, a new task will start. Inside the task I have created an instance of the form2 and show form2. I am calling the showData Method of Form2.



//Form1
public event TickHandler Tick;
public EventArgs e = null;
public delegate void TickHandler(int a1, EventArgs e);

private void button1_Click(object sender, EventArgs e)

Task.Factory.StartNew(() =>

Form2 form2 = new Form2();
form2.Show();



//Form2
public void showData(Form1 m)

m.Tick += new Form1.TickHandler(test);


public void test(int a1,EventArgs e)

Task.Factory.StartNew(() =>

for (int i = a1; i < 1000; i++)

label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

);










share|improve this question



















  • 1





    Invoke when you do anything on UI elements including new Form2()

    – kenny
    Mar 24 at 10:58











  • I added Invoke but it showing error message on test method in form2 like this 'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

    – Ram
    Mar 24 at 11:31






  • 1





    move that code to execute on the Loaded event on the form

    – kenny
    Mar 24 at 11:34


















-2















In my Windows Form application I have created 2 Forms. In form 1 when I click button1, a new task will start. Inside the task I have created an instance of the form2 and show form2. I am calling the showData Method of Form2.



//Form1
public event TickHandler Tick;
public EventArgs e = null;
public delegate void TickHandler(int a1, EventArgs e);

private void button1_Click(object sender, EventArgs e)

Task.Factory.StartNew(() =>

Form2 form2 = new Form2();
form2.Show();



//Form2
public void showData(Form1 m)

m.Tick += new Form1.TickHandler(test);


public void test(int a1,EventArgs e)

Task.Factory.StartNew(() =>

for (int i = a1; i < 1000; i++)

label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

);










share|improve this question



















  • 1





    Invoke when you do anything on UI elements including new Form2()

    – kenny
    Mar 24 at 10:58











  • I added Invoke but it showing error message on test method in form2 like this 'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

    – Ram
    Mar 24 at 11:31






  • 1





    move that code to execute on the Loaded event on the form

    – kenny
    Mar 24 at 11:34














-2












-2








-2








In my Windows Form application I have created 2 Forms. In form 1 when I click button1, a new task will start. Inside the task I have created an instance of the form2 and show form2. I am calling the showData Method of Form2.



//Form1
public event TickHandler Tick;
public EventArgs e = null;
public delegate void TickHandler(int a1, EventArgs e);

private void button1_Click(object sender, EventArgs e)

Task.Factory.StartNew(() =>

Form2 form2 = new Form2();
form2.Show();



//Form2
public void showData(Form1 m)

m.Tick += new Form1.TickHandler(test);


public void test(int a1,EventArgs e)

Task.Factory.StartNew(() =>

for (int i = a1; i < 1000; i++)

label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

);










share|improve this question
















In my Windows Form application I have created 2 Forms. In form 1 when I click button1, a new task will start. Inside the task I have created an instance of the form2 and show form2. I am calling the showData Method of Form2.



//Form1
public event TickHandler Tick;
public EventArgs e = null;
public delegate void TickHandler(int a1, EventArgs e);

private void button1_Click(object sender, EventArgs e)

Task.Factory.StartNew(() =>

Form2 form2 = new Form2();
form2.Show();



//Form2
public void showData(Form1 m)

m.Tick += new Form1.TickHandler(test);


public void test(int a1,EventArgs e)

Task.Factory.StartNew(() =>

for (int i = a1; i < 1000; i++)

label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

);







c# task begininvoke






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 11:27









Han

2,34821525




2,34821525










asked Mar 24 at 10:55









RamRam

25212




25212







  • 1





    Invoke when you do anything on UI elements including new Form2()

    – kenny
    Mar 24 at 10:58











  • I added Invoke but it showing error message on test method in form2 like this 'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

    – Ram
    Mar 24 at 11:31






  • 1





    move that code to execute on the Loaded event on the form

    – kenny
    Mar 24 at 11:34













  • 1





    Invoke when you do anything on UI elements including new Form2()

    – kenny
    Mar 24 at 10:58











  • I added Invoke but it showing error message on test method in form2 like this 'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

    – Ram
    Mar 24 at 11:31






  • 1





    move that code to execute on the Loaded event on the form

    – kenny
    Mar 24 at 11:34








1




1





Invoke when you do anything on UI elements including new Form2()

– kenny
Mar 24 at 10:58





Invoke when you do anything on UI elements including new Form2()

– kenny
Mar 24 at 10:58













I added Invoke but it showing error message on test method in form2 like this 'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

– Ram
Mar 24 at 11:31





I added Invoke but it showing error message on test method in form2 like this 'Invoke or BeginInvoke cannot be called on a control until the window handle has been created.'

– Ram
Mar 24 at 11:31




1




1





move that code to execute on the Loaded event on the form

– kenny
Mar 24 at 11:34






move that code to execute on the Loaded event on the form

– kenny
Mar 24 at 11:34













1 Answer
1






active

oldest

votes


















1














As kenny suggested i have modified the code. now it running how i am expected.



 public partial class Form1 : Form


public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

Task.Factory.StartNew(() =>

Action act1 = (() =>

Form2 form2 = new Form2();
form2.StartPosition = FormStartPosition.CenterParent;
form2.Show();
);
this.BeginInvoke(act1);
);




// FORM2



private void Form2_Load(object sender, EventArgs e)

test(1);

public void test(int a1)

Task.Factory.StartNew(() =>

for (int i = a1; i < 1000; i++)

label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

);



Once again thanks Kenny






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323069%2fhow-to-invoke-a-form-inside-another-form-task%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    As kenny suggested i have modified the code. now it running how i am expected.



     public partial class Form1 : Form


    public Form1()

    InitializeComponent();

    private void button1_Click(object sender, EventArgs e)

    Task.Factory.StartNew(() =>

    Action act1 = (() =>

    Form2 form2 = new Form2();
    form2.StartPosition = FormStartPosition.CenterParent;
    form2.Show();
    );
    this.BeginInvoke(act1);
    );




    // FORM2



    private void Form2_Load(object sender, EventArgs e)

    test(1);

    public void test(int a1)

    Task.Factory.StartNew(() =>

    for (int i = a1; i < 1000; i++)

    label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

    );



    Once again thanks Kenny






    share|improve this answer



























      1














      As kenny suggested i have modified the code. now it running how i am expected.



       public partial class Form1 : Form


      public Form1()

      InitializeComponent();

      private void button1_Click(object sender, EventArgs e)

      Task.Factory.StartNew(() =>

      Action act1 = (() =>

      Form2 form2 = new Form2();
      form2.StartPosition = FormStartPosition.CenterParent;
      form2.Show();
      );
      this.BeginInvoke(act1);
      );




      // FORM2



      private void Form2_Load(object sender, EventArgs e)

      test(1);

      public void test(int a1)

      Task.Factory.StartNew(() =>

      for (int i = a1; i < 1000; i++)

      label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

      );



      Once again thanks Kenny






      share|improve this answer

























        1












        1








        1







        As kenny suggested i have modified the code. now it running how i am expected.



         public partial class Form1 : Form


        public Form1()

        InitializeComponent();

        private void button1_Click(object sender, EventArgs e)

        Task.Factory.StartNew(() =>

        Action act1 = (() =>

        Form2 form2 = new Form2();
        form2.StartPosition = FormStartPosition.CenterParent;
        form2.Show();
        );
        this.BeginInvoke(act1);
        );




        // FORM2



        private void Form2_Load(object sender, EventArgs e)

        test(1);

        public void test(int a1)

        Task.Factory.StartNew(() =>

        for (int i = a1; i < 1000; i++)

        label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

        );



        Once again thanks Kenny






        share|improve this answer













        As kenny suggested i have modified the code. now it running how i am expected.



         public partial class Form1 : Form


        public Form1()

        InitializeComponent();

        private void button1_Click(object sender, EventArgs e)

        Task.Factory.StartNew(() =>

        Action act1 = (() =>

        Form2 form2 = new Form2();
        form2.StartPosition = FormStartPosition.CenterParent;
        form2.Show();
        );
        this.BeginInvoke(act1);
        );




        // FORM2



        private void Form2_Load(object sender, EventArgs e)

        test(1);

        public void test(int a1)

        Task.Factory.StartNew(() =>

        for (int i = a1; i < 1000; i++)

        label1.Invoke(new MethodInvoker(delegate label1.Text = i.ToString(); ));

        );



        Once again thanks Kenny







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 12:05









        RamRam

        25212




        25212





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323069%2fhow-to-invoke-a-form-inside-another-form-task%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해