What's wrong with Environment.UserInteractive?

406 views
Skip to first unread message

Manuel Pallier

unread,
Sep 7, 2017, 1:44:53 AM9/7/17
to Particular Software
Helpful information to include
Product name: NServiceBus
Version: 6.4.0
Stacktrace: -
Description:

I noticed that the documentation page "Windows Service Hosting" (https://docs.particular.net/nservicebus/hosting/windows-service) and it's sample page (https://docs.particular.net/samples/hosting/windows-service/) was recently modified to use some non-trivial code to detect if the application was started as a service or manually. What's wrong with the simple call to "Environment.UserInteractive" that was used before?

Simon Cropp

unread,
Sep 7, 2017, 8:31:51 AM9/7/17
to Particular Software
Manuel

We are moving over to supporting netstandard and dot net core. In testing those scenarios I discovered that Environment.UserInteractive always returns true on netcore. And it seems to be by design, or at least in discussions i read it was not discussed as a bug, eg https://github.com/dotnet/corefx/issues/6024#issuecomment-310816129. The work around suggested by many people is "just pass in a command line param that indicates it is a service". TBH i was not a fan of this suggestion. So i coded a solution that works on both normal .net and netcore. Yes it would be possible for us to say "use Environment.UserInteractive if on normal .net", but i was concerned about the ramifications of people trying to have to do the same trouble shooting i did, when they eventually move to netcore and have forgotten the caveats on UserInteractive.

Any suggestions on a better approach? Anything i have missed?

Manuel Pallier

unread,
Sep 7, 2017, 8:46:34 AM9/7/17
to Particular Software
Ok, thanks for the explanation. I'd just suggest to add a small note to the documentation pages that says something like "This is required because the popular approach to use Environment.UserInteractive does not work in .NET core".

Btw, the page https://docs.particular.net/nservicebus/hosting/nservicebus-host/ still shows the use of Environment.UserInteractive in the default critical error action of NServiceBus Host. Assuming you also changed the code in NServiceBus Host you'd might want to update that page too.

Simon Cropp

unread,
Sep 7, 2017, 8:58:21 AM9/7/17
to Particular Software
> I'd just suggest to add a small note to the documentation pages

Agreed. i will do that and post an update back here

> Assuming you also changed the code in NServiceBus Host you'd might want to update that page too.

Given the NSB host will not be supported on netcore i am not sure the change would be helpful

Manuel Pallier

unread,
Sep 7, 2017, 9:00:27 AM9/7/17
to Particular Software
Given the NSB host will not be supported on netcore i am not sure the change would be helpful

Ok, didn't know that. Then of course no change is needed there.

Simon Cropp

unread,
Sep 11, 2017, 5:45:47 PM9/11/17
to Particular Software
note added in front of the ServiceHelper snippet https://docs.particular.net/nservicebus/hosting/windows-service

Manuel Pallier

unread,
Sep 12, 2017, 1:18:11 AM9/12/17
to Particular Software
Thanks, but there seems to be a "no" or "not" missing in

Note that if there is intention to target .NET Core, then Environment.UserInteractive can be used.

Andreas Ohlund

unread,
Sep 12, 2017, 8:16:57 AM9/12/17
to Particular Software
Thanks Manuel, I've raised a PR to address this 


Cheers,

Andreas

Simon Cropp

unread,
Sep 12, 2017, 10:04:27 PM9/12/17
to Particular Software
Thanks for keeping us on our toes Manuel

BTW, although it is fully our responsibility, if u ever want to do small edits on pages there is an edit button near the top right of every page.


Reply all
Reply to author
Forward
0 new messages