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)
{
}
}
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
More C# MCQ Questions