?
Solved

C# Threaded MDI Children

Posted on 2006-06-29
6
Medium Priority
?
832 Views
Last Modified: 2012-06-21
I have a form that is an MDI parent and when a user selects a tool from the menu, it spawns a mdiChild form.
How do I make that new mdiChild a thread or am I doing it all wrong?
I want it to be a seperate thread so if it crashes, the entire program does not crash.

0
Comment
Question by:flam79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 

Author Comment

by:flam79
ID: 17013773
I'm not sure how this point system works, this is my first time posting a question but since I need an answer asap, i am putting 500 pts. is that ok?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17015623
.NET Framework allows to create UI elements like form or control only in the main application thread. It is impossible to do what you want.
You can run worker thread, which make some work not related to UI - calculations, file access, database, sockets ets.
Notice that when worker thread crashes, the whole program crashes as well.  If you have bug in the program you need to fix it, there is no other way.
0
 

Author Comment

by:flam79
ID: 17015705
Ok, thanks for the input AlexFM, let me ask this then..

I have this code here

  label2.Text = "Eating resources.";
           
            for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
            {
                label2.Text = i.ToString();
               Application.DoEvents();

            }
            label2.Text = "Done";

I want to run tha in a thread but i can't alter the label2 object because I get cross-threading errors.
I want to run that for loop in a thread, how would I go about doing that?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 17015719
The following article answers your question:
http://www.codeproject.com/csharp/workerthread.asp

Pay attention to using of Invoke method to pass information from worker to main thread.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
A short article about problems I had with the new location API and permissions in Marshmallow
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question