Solved

C# Threaded MDI Children

Posted on 2006-06-29
6
823 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
Comment Utility
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
Comment Utility
.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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
zeroMAx challenge 20 76
mergeTwo  challenge 13 71
wordmultiple challenge 12 89
control image tags in a string ? 12 58
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now