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;
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
add a comment |
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
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
add a comment |
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
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
c# task begininvoke
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 24 at 12:05
RamRam
25212
25212
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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