Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Threading.Thread - Unable to run as foreground thread. #15766

Closed
sinclairzx81 opened this issue Nov 23, 2015 · 3 comments
Closed

System.Threading.Thread - Unable to run as foreground thread. #15766

sinclairzx81 opened this issue Nov 23, 2015 · 3 comments
Assignees
Milestone

Comments

@sinclairzx81
Copy link

Hi there,

For System.Threading.Thread : 4.0.0-beta-23516, there appears to be a problem having the thread execute as a foreground thread on DNX (1.0.0-beta6-12120). The property IsBackground does not appear to have any bearing on how this thread is treated, with it seemingly behaving like a background thread with IsBackground reporting false. The end result is the caller must explicitly join on the thread to prevent a process exiting, which is not typical behavior.

I am mindful that this may be related to DNX, or potentially functionality under review for corefx with consideration to varying platforms.

MSDN: CLR Thread.IsBackground Property
https://msdn.microsoft.com/en-us/library/system.threading.thread.isbackground%28v=vs.110%29.aspx

Below, the expected behavior would be to have the process stay running until this thread exits.

using System;

namespace example {

    public class Program {

        public static void Main(string[] args) {

            // 4.0.0-beta-23516
            var t = new System.Threading.Thread(() => {

                var running = true;

                while(running) {

                    // we do not want this thread to exit.
                }

            });

            t..Start();

            // t.Join(); // this shouldn't be necessary for IsBackground = false
        }
    }
}

Many Thanks

@akoeplinger
Copy link
Member

@sinclairzx81
Copy link
Author

@akoeplinger thanks

@stephentoub
Copy link
Member

Thanks. Closing as a dup of https://github.com/dotnet/coreclr/issues/1648

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rc2 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants