Skip to content

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

@sinclairzx81

Description

@sinclairzx81

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions