Solved

C# Threaded MDI Children

Posted on 2006-06-29
6
826 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
This article will show, step by step, how to integrate R code into a R Sweave document
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

832 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