Question: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) { } }
A lblMessage.Text will be set to "Hello from Thread Pool".
B An InvalidOperationException will be thrown for the function ShowMessage as the UI can be updated only from the UI thread.
C Behavior will vary depending on the form loaded.
D None of these.
+ AnswerB
+ Report