Solved

C# Threaded MDI Children

Posted on 2006-06-29
6
828 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
  • 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 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

830 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