Click here to Skip to main content
15,896,118 members
Home / Discussions / C#
   

C#

 
AnswerRe: Display a Custom Form Modally Pin
Mycroft Holmes13-Apr-09 14:26
professionalMycroft Holmes13-Apr-09 14:26 
GeneralRe: Display a Custom Form Modally Pin
sevensilly14-Apr-09 5:33
sevensilly14-Apr-09 5:33 
Questionproblem with datagrid and column Pin
behzadcp13-Apr-09 8:25
professionalbehzadcp13-Apr-09 8:25 
AnswerRe: problem with datagrid and column Pin
Faisal Khatri13-Apr-09 11:10
Faisal Khatri13-Apr-09 11:10 
GeneralRe: problem with datagrid and column Pin
behzadcp13-Apr-09 16:50
professionalbehzadcp13-Apr-09 16:50 
QuestionHow to load images on background transperantly? Pin
Supra213-Apr-09 6:56
Supra213-Apr-09 6:56 
AnswerRe: How to load images on background transperantly? Pin
EliottA13-Apr-09 7:09
EliottA13-Apr-09 7:09 
QuestionThreads and Windows Forms [modified] Pin
kikeman13-Apr-09 6:23
kikeman13-Apr-09 6:23 
Hi,

I am just wondering something related to safety:

Is it safe to create Windows forms from separated Threads (System.Threading) ?

The Thread is created from a UserControl (from a click button for example).

The point is that when the thread is started I need to show some "custom forms" (Windows.Forms) that are created inside the thread in order to promp to the user the -OK and -CANCEL options in order to take a desition from there.

The thread is a single thread apartment (STA)

Example:
namespace ThreadTestandForms
{
    public partial class FormGUI : UserControl
    {

        private void button2_Click(object sender, EventArgs e)
        {
            Thread ThreadSendParts;
            ThreadSendParts = new Thread(new ThreadStart(RunsOnThread));
            ThreadSendParts.SetApartmentState(ApartmentState.STA);

            //I want to use a good priority.
            ThreadSendParts.Priority = ThreadPriority.Highest;
            ThreadSendParts.Start();    //TO KEEP A RESPONSIVE UI

            FrmSentPrtPgres.ShowDialog();  //I need to show a modal dialog after running the thread.
        }


        private void RunsOnThread()
        {
            for (int i = 0; i <= 100; i += 10) //SIMULATE HEAVY PROCESS
            {
                Thread.Sleep(200);  //SIMULATE HEAVY PROCESS

                //This method uses BeginInvoke and InvokeRequired
                ShowProgress("My Progress Status", i);

                //Example of doing some custom form with some custom conditions.
                FrmMyMessage MyForm = new FrmMyMessage("Do you want do this or that?");

                //show message stop exectuting until user takes a decision.
                DialogResult DLRes = MyForm.ShowDialog();

                if (DLRes == DialogResult.OK)
                {
                    //do something this
                }
                else
                {
                    //do something that
                }
            }

            //Execute some extra things when finishing the thread.
            //This method uses BeginInvoke and InvokeRequired
            ThreadCompleted();
        }
    }  
}

Regards,

modified on Monday, April 13, 2009 6:11 PM

AnswerRe: Threads and Windows Forms Pin
Dave Kreskowiak13-Apr-09 8:52
mveDave Kreskowiak13-Apr-09 8:52 
GeneralRe: Threads and Windows Forms Pin
kikeman13-Apr-09 10:05
kikeman13-Apr-09 10:05 
GeneralRe: Threads and Windows Forms Pin
Dave Kreskowiak13-Apr-09 10:39
mveDave Kreskowiak13-Apr-09 10:39 
GeneralRe: Threads and Windows Forms Pin
kikeman13-Apr-09 11:10
kikeman13-Apr-09 11:10 
QuestionArray of Structs overwrite problem Pin
Bruce Coward13-Apr-09 5:41
Bruce Coward13-Apr-09 5:41 
AnswerRe: Array of Structs overwrite problem Pin
Luc 64801113-Apr-09 6:06
Luc 64801113-Apr-09 6:06 
GeneralRe: Array of Structs overwrite problem Pin
Bruce Coward13-Apr-09 6:24
Bruce Coward13-Apr-09 6:24 
GeneralRe: Array of Structs overwrite problem Pin
Luc 64801113-Apr-09 7:17
Luc 64801113-Apr-09 7:17 
AnswerRe: Array of Structs overwrite problem Pin
Gideon Engelberth13-Apr-09 8:51
Gideon Engelberth13-Apr-09 8:51 
GeneralRe: Array of Structs overwrite problem Pin
Luc 64801113-Apr-09 9:01
Luc 64801113-Apr-09 9:01 
AnswerRe: Array of Structs overwrite problem Pin
Alan N13-Apr-09 9:49
Alan N13-Apr-09 9:49 
GeneralRe: Array of Structs overwrite problem Pin
Luc 64801113-Apr-09 10:29
Luc 64801113-Apr-09 10:29 
QuestionCross-thread error. Pin
Fired.Fish.Gmail13-Apr-09 4:58
Fired.Fish.Gmail13-Apr-09 4:58 
AnswerRe: Cross-thread error. Pin
Colin Angus Mackay13-Apr-09 5:06
Colin Angus Mackay13-Apr-09 5:06 
GeneralRe: Cross-thread error. Pin
Fired.Fish.Gmail13-Apr-09 5:20
Fired.Fish.Gmail13-Apr-09 5:20 
GeneralRe: Cross-thread error. Pin
Henry Minute13-Apr-09 5:22
Henry Minute13-Apr-09 5:22 
AnswerRe: Cross-thread error. Pin
Luc 64801113-Apr-09 5:39
Luc 64801113-Apr-09 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.