Solved

C# Threaded MDI Children

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to split this in C++ 4 93
topping1 challenge 7 72
what is the main difference between git clone and fetch ann pull and push commands 2 67
SUM 2 INTEGER ARRAYS INTO 1 10 93
This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

932 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

14 Experts available now in Live!

Get 1:1 Help Now