MCQs > IT & Programming > C# > What will be the output if in a WinForms application, the following code is executed in the Load event of a form? Assume this form has lblMessage as a Label Control. private void Form1_Load(object sender, EventArgs e) { try { ThreadPool.QueueUserWorkItem(ShowMessage,null); } catch (Exception ex) { } } private void ShowMessage(object obj) { try { lblMessage.Text = 'Hello from Thread Pool'; } catch (Exception ex) { } }

C# MCQs

What will be the output if in a WinForms application, the following code is executed in the Load event of a form? Assume this form has lblMessage as a Label Control.

private void Form1_Load(object sender, EventArgs e)

{

    try

    {

        ThreadPool.QueueUserWorkItem(ShowMessage,null);

    }

    catch (Exception ex)

    {

    }

}

private void ShowMessage(object obj)

{

    try

    {

        lblMessage.Text = "Hello from Thread Pool";

    }

    catch (Exception ex)

    {

    }

}

Answer

Correct Answer: An InvalidOperationException will be thrown for the function ShowMessage as the UI can be updated only from the UI thread.

Explanation:

Note: This Question is unanswered, help us to find answer for this one

C# Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

C# Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it