Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:11:17+00:00 2026-05-29T05:11:17+00:00

I am learning the behavior of GUI Thread vs Worker Thread. So I create

  • 0

I am learning the behavior of GUI Thread vs Worker Thread.
So I create a class which will update GUI Control from different thread …

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("\n\n\n");

        Thread.CurrentThread.Name = "Parent Thread";
        label1.Text = "I am One";
        System.Diagnostics.Debug.WriteLine("[button1_Click] label1.Text :" + label1.Text);



        Thread _Thred = new Thread(FunctionCallBack);
        _Thred.Name = "Child Thread";
        _Thred.Start();
        _Thred.Join();

        label1.Text = "I am Three";
        System.Diagnostics.Debug.WriteLine("[button1_Click] label1.Text :" + label1.Text);

    }

    void FunctionCallBack()
    {
        MethodInvoker _Method = delegate()
        {
            label1.Text = "I am Two";
            System.Diagnostics.Debug.WriteLine("[FunctionCallBack] label1.Text :" + label1.Text);
        };


        System.Diagnostics.Debug.WriteLine("[FunctionCallBack] label1.BeginInvoke(_Method) : Executed");            
        label1.BeginInvoke(_Method);

        /*
        System.Diagnostics.Debug.WriteLine("[FunctionCallBack] label1.Invoke(_Method) : Executed");
        label1.Invoke(_Method);
        */
    }
}

When I click Button, I get this Output

Output when I using BeginInvoke Method
-------------------------------------- 

[button1_Click] label1.Text :I am One
[FunctionCallBack] label1.BeginInvoke(_Method) : Executed
The thread 'Child Thread' (0xfb8) has exited with code 0 (0x0).
[button1_Click] label1.Text :I am Three
[FunctionCallBack] label1.Text :I am Two

I change my code by using Invoke method instead of calling BeginInvoke method.

System.Diagnostics.Debug.WriteLine("[FunctionCallBack] label1.Invoke(_Method) : Executed");
label1.Invoke(_Method);

I get below output and program cease.

Output when I using Invoke Method 
----------------------------------

[button1_Click] label1.Text :I am One
[FunctionCallBack] label1.Invoke(_Method) : Executed

Please Let me know that, is this situation which I face now call dead lock?
If you say yes , do I have any chance to use Control.Invoke method again ?

Especially , for this kind of situation, do I have only one chance which I have to use Control.BeginInvoke method?

Every suggestion will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:11:18+00:00Added an answer on May 29, 2026 at 5:11 am

    The issue is with your button1_Click method. It’s called on the GUI thread and it blocks on _Thread.Join. You should remove this and not wait for the thread to finish; this is the whole idea of executing something on another thread.

    The reason why the first case works, is that the worker thread doesn’t wait for the GUI thread to update and then returns so that GUI thread is then unblocked.

    With the second case, the worker thread waits for the GUI to update, which it can’t because it is blocked on wait for the worker to finish. Yes, its a dead lock, but the issue is really with the click method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learning from my last question , most member names seem to get included in
Will learning C++ help me build native applications with good speed? Will it help
For learning and demonstrating, I need a macro which prints its parameter and evaluates
While learning different languages, I've often seen objects allocated on the fly, most often
I'm slowly learning how to apply CakePHP's Translate Behavior and I think I've grasped
I'm learning the Cinder framework. There is a class Texture in this framework, and
I understand the concept behind DI, but I'm just learning what different IoC containers
I'm curious about this behavior and maybe its just because I've come from using
I'm learning grails from the book Grails In Action and I'm trying to run
I've started learning C# and I'm a bit confused about the behavior that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.