Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Red Mike
Jul 11, 2011
In case I wasn't clear with my reply, what I mean is that most of those complaints don't reflect badly on the company in my opinion. Management is hard: bad choices will be made, technical debt will happen, documentation will be lacking. If you're complaining about these things as a coder and are saying you can't do your job because of it, then either: it's bad beyond belief (which I don't think is the case from what I've heard) or you're not experienced enough yet. If you are experienced enough to work through them, and you're still complaining, I'd recommend becoming a manager (however bad you are at management) and trying to put a stop to it yourself.

As a coder, they're all things you work around as best as you can or bring to the attention of managers when it gets too much to work around. If they won't do anything about it, then you do the job anyway and contribute to the technical debt, bad documentation, and bad choices in doing so.
As a manager, they're all things you try and minimise to the best of your ability. When you're blocked by other managers, by tasks, by deadlines, etc, you do the job anyway and let it sit there and ferment while trying to keep the project on-schedule, and bad decisions will make that more and more impossible as time goes on.

e: Also what the previous poster said. Worse, I just mentally substitute 'refactor an entire codebase' with 'introduce a million bugs'. That poo poo should be done in discrete parts that are launched independently so you can at least find the bugs gradually and without interactions that might make it harder to debug.


In .NET news, I've got a project at work that's using the latest pre-Core ASP.NET, and I've been asked to consider switching to ASP.NET Core in order to switch our hosting from Windows to Linux (EC2 Windows support is woefully bad), how bad of an idea is this considering we depend on a fairly large number of libraries like Entity Framework, various NoSQL libraries, etc? And more importantly, how much has the architecture changes and are all the other developers have to learn an entirely new set of gotchas to work with it successfully?

Adbot
ADBOT LOVES YOU

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Red Mike posted:

e: Also what the previous poster said. Worse, I just mentally substitute 'refactor an entire codebase' with 'introduce a million bugs'.

But enough about .NET Core :v:

Red Mike posted:

In .NET news, I've got a project at work that's using the latest pre-Core ASP.NET, and I've been asked to consider switching to ASP.NET Core in order to switch our hosting from Windows to Linux (EC2 Windows support is woefully bad), how bad of an idea is this considering we depend on a fairly large number of libraries like Entity Framework, various NoSQL libraries, etc? And more importantly, how much has the architecture changes and are all the other developers have to learn an entirely new set of gotchas to work with it successfully?

Have you tried running it on Mono? ASP.NET compatibility with Mono can be iffy but it might be worth trying that to see if what you have right now just works on Linux, rather than rewriting it at all.

ASP.NET Core is a not a simple upgrade from 4.6. It's going to probably require a bit of work to move it over, depending on how complex it is. If you want to run it on .NET Core, that would mean having to upgrade to EF Core (I think EF 6 can be run on ASP.NET Core, but only if you run with the full .NET Framework or Mono), and that would require a bit of refactoring too, and it's also not exactly production safe just yet IMO.

B-Nasty
May 25, 2005

Red Mike posted:

In .NET news, I've got a project at work that's using the latest pre-Core ASP.NET, and I've been asked to consider switching to ASP.NET Core in order to switch our hosting from Windows to Linux (EC2 Windows support is woefully bad), how bad of an idea is this considering we depend on a fairly large number of libraries like Entity Framework, various NoSQL libraries, etc? And more importantly, how much has the architecture changes and are all the other developers have to learn an entirely new set of gotchas to work with it successfully?

Bad, at least how you described it. It sounds like you're trying to develop your way out of a cost/infrastructure challenge, and underestimating how much time and frustration that will involve for your dev team. Unless your app is fairly trivial, of course.

At this point in time, I don't see a ton of compelling reasons to switch a large, working ASP.NET 4.X application to Core, but I would consider anything green-field to be work taking a look.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
In an UWA, I want to use a Polyline for a linechart and use relative coordinates and use Stretch="Fill", so that I don't have to recalculate point coordinates every time when I resize or whatever. The issue however is that say if the points used for Y axis goes from 0.25 to 0.75, it'll normalize it and stretch it as much as possible instead of leaving 25% on top and bottom blank as the min/max Y coordinates of the points suggest. A cheap temporary fix right now is to draw a first segment from top to bottom. How can I do this properly, because the cheap fix leaves an artifact.

--edit:
Basically, this is how it is supposed to look, but uses the cheap fix:
http://i.imgur.com/L9sYaHZ.png

This happens when I don't add a first segment going from 0,0 to 0,1:
http://i.imgur.com/bkpZYrf.png

Combat Pretzel fucked around with this message at 21:53 on Jul 17, 2016

Red Mike
Jul 11, 2011

B-Nasty posted:

Bad, at least how you described it. It sounds like you're trying to develop your way out of a cost/infrastructure challenge, and underestimating how much time and frustration that will involve for your dev team. Unless your app is fairly trivial, of course.

At this point in time, I don't see a ton of compelling reasons to switch a large, working ASP.NET 4.X application to Core, but I would consider anything green-field to be work taking a look.

Well nothing's final right now, but the original reasoning was 'this is obviously just a new version of ASP.NET'. I..may have failed explaining to them how that's not true, so I was asked to investigate anyway to see if there's any major roadblocks, since running on Linux would be a huge benefit for us (for reasons I can't get into). We've already got a couple cons on the board, which are the huge amount of time we'd have to allocate to switch, and the doubling of work for developers during the transition.

The app is definitely not trivial, so yeah this would be at least a couple months just to get the basic functionality working again and devs even half-competent, even ignoring library issues.


Drastic Actions posted:

Have you tried running it on Mono? ASP.NET compatibility with Mono can be iffy but it might be worth trying that to see if what you have right now just works on Linux, rather than rewriting it at all.

ASP.NET Core is a not a simple upgrade from 4.6. It's going to probably require a bit of work to move it over, depending on how complex it is. If you want to run it on .NET Core, that would mean having to upgrade to EF Core (I think EF 6 can be run on ASP.NET Core, but only if you run with the full .NET Framework or Mono), and that would require a bit of refactoring too, and it's also not exactly production safe just yet IMO.

We had a test of running it on Mono, and just constantly ran into issues. The amount of requests a single instance could handle dropped down to less than half, and it was quite unstable after running for a while. The memory usage also shot up a lot, which is down to problems we have in the code (and problems in Entity Framework and MySQL Connector) but that shoots up on our current version anyway. :v: In the end, running on Mono basically meant we needed over twice the number of instances, which ended up being more expensive, and it was more unstable, which meant nearly three times the number of instances for better failover.

Having to switch to a different EF version pretty much blocks a transition, since we're already planning to move off of EF to a less popular library which is probably going to support Core even less. Ah well, I just need to compile all of the reasons into a handy list so I can try and convince everyone that it's a bad idea now. Thanks.

mystes
May 31, 2006

Combat Pretzel posted:

In an UWA, I want to use a Polyline for a linechart and use relative coordinates and use Stretch="Fill", so that I don't have to recalculate point coordinates every time when I resize or whatever. The issue however is that say if the points used for Y axis goes from 0.25 to 0.75, it'll normalize it and stretch it as much as possible instead of leaving 25% on top and bottom blank as the min/max Y coordinates of the points suggest. A cheap temporary fix right now is to draw a first segment from top to bottom. How can I do this properly, because the cheap fix leaves an artifact.

--edit:
Basically, this is how it is supposed to look, but uses the cheap fix:
http://i.imgur.com/L9sYaHZ.png

This happens when I don't add a first segment going from 0,0 to 0,1:
http://i.imgur.com/bkpZYrf.png
I don't know a ton about WPF and nothing about UWA, but assuming they work the same way, I think in this case you want to add the polyline to a canvas in a viewbox and use the viewbox to handle the resizing or something like that?

mystes fucked around with this message at 23:02 on Jul 17, 2016

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
I guess I'll be looking into this.

--edit: Results in a hilariously large user control. From what I can quickly figure out is that Viewboxes are supposed to be used as root element in a window only.
--edit2: Got it to work somehow. It does always scale uniformly for whatever reason. But it also scales stroke thickness, so it's not really useful visually.

Combat Pretzel fucked around with this message at 01:18 on Jul 18, 2016

Mr Shiny Pants
Nov 12, 2012
I do find it weird that one of the poster childs for software development has this many issues.

I mean sure, if your core business is not software development I can understand processes having warts, but as a software company that builds tools to do software development?

I don't know, strikes me as odd.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
You talking about Microsoft? If so, this whole UWA story stinks to high hell. Look at the type of Win32 applications they've churned out with Windows releases in the past, and then look at the WinRT ones, which are a travesty. I'm almost to believe that their internal developers are struggling with these new IO interfaces that came with the sandboxing. That and the inconsistency between core UI elements, which suggests that they don't even have a common UI toolkit to develop with (like MFC, ATL, WTL and that poo poo in the past). Can't even wait to see what this UWA version of the file explorer will be like.

Also, this artificial walling off of a couple of important WinRT APIs, making it improssible to spawn a WinRT user interface outside the store. What for?

As for my personal problem with that Polyline, I figure I'll have to write a custom container that calculates appropriate margins on the fly.

Combat Pretzel fucked around with this message at 20:33 on Jul 18, 2016

Gul Banana
Nov 28, 2003

i don't think microsoft has ever been known for having consistent, attractive user interfaces across their product line.

ljw1004
Jan 18, 2005

rum

Red Mike posted:

Ah well, I just need to compile all of the reasons into a handy list so I can try and convince everyone that it's a bad idea now. Thanks.

Red Mike, my team at Microsoft is the one dealing with adoption and migration of .NET and .NET Core. If you'd like to run over your handy list with us, or discuss in more depth, send me an email at lwischik@microsoft.com. Same goes for anyone else of course.


(Emailing me isn't the right place for filing issues, or requesting/complaining about specific features or designs, or missing documentation. Those specific individual technical things are better tracked on github or posted on .NET team blog. But when it comes down to individual circumstances for the all-up migration decisions, I figure it might be easiest to email.)



PS. Is work at Microsoft like that reddit thread? Yes and no. Yes more than ever we have to justify through evidence that our work will have customer benefit. Yes like in every large software project ever there are irritating build processes and historical cruft. No because in my ten years in the developer division I've only ever been surrounded by professional and good-natured colleagues.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!

Gul Banana posted:

i don't think microsoft has ever been known for having consistent, attractive user interfaces across their product line.
This UWP and XAML stuff certainly makes it way easier than before, tho. But hey, instead of a common toolkit, that'd ideally be also available to the third party developer, every system app implements the variety of UI elements on their own and always slightly different in look and/or functionality.

Essential
Aug 14, 2003
I'm trying to convert a UTC date, on an azure cloud server, to an appropriate timezone epoch date and I just cannot get it right. For instance, if I have 1/1/2016 00:00:00 UTC I need to convert that to 1/1/2016 00:00:00 PST (ultimately any timezone, just PST now for testing) and then get the epoch value of that. This is all happening on azure cloud servers and my mind is fried between trying to run it local and running it on the server and not getting the expected results.

The correct epoch value for 1/1/2016 00:00:00 PST is 1451635200.

An example I tried was to determine the offset from UTC and subtracting that from the unix epoch value. The problem is this does not take into consideration whether DST is on/off. To determine DST I was trying to use the IsDaylightSavings datetime method, however when I convert 1/1/2016 UTC using TimeZoneInfo PST the value becomes 12/31/2015 4pm PST, which is not the date I'm trying to use.

At this point my mind is mush and I can't help but feel I'm missing a very easy way to do this and/or I'm missing something obvious. I've really struggled with testing this as my work laptop is PST but once uploaded to azure it changes to UTC and my eye's are rolling at this point.

Code to set "Standard" offset (Offset for PST is -7 hours, 25200 seconds, DST is -8 hours, 28800 seconds) The code below does not work as intended because it will set the offset based on the server datetime, not the datetime passed in. At the moment the offset is 25200 based on utc server date:
code:
            switch (OfficeTimeZone)
            {
                case "PST":
                    tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

                    convertedDateTime = TimeZoneInfo.ConvertTime(ServerDate, TimeZoneInfo.Local, tz);
                    offset = tz.GetUtcOffset(convertedDateTime);
                    OfficeOffset = (int)(offset.TotalSeconds * -1);
                    break;

                default:
                    OfficeTimeZone = "PST";
                    tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

                    convertedDateTime = TimeZoneInfo.ConvertTime(ServerDate, TimeZoneInfo.Local, tz);
                    offset = tz.GetUtcOffset(convertedDateTime);
                    OfficeOffset = (int)(offset.TotalSeconds * -1);
                    break;
            }
Code to get epoch date:
code:
            var unixTime = StartDate.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            long utcEpoch = (long)unixTime.TotalSeconds;
            return (utcEpoch + OfficeOffset);
I started to add something to include the daylightsavingsoffset but fails as explained above (1/1/2016 UTC becomes 12/31/2015 04:00:00pm PST):
code:
            int daylightSavingsOffset = 0;
            TimeZoneInfo tz;

            switch (OfficeTimeZone)
            {
                case "PST":
                    tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

                    if (!StartDate.IsDaylightSavingTime())
                    {
                        daylightSavingsOffset = -3600;
                    }

                    break;

                default:
                    tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

                    if (!StartDate.IsDaylightSavingTime())
                    {
                        daylightSavingsOffset = -3600;
                    }
                    break;
            }

            var unixTime = StartDate.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            long utcEpoch = (long)unixTime.TotalSeconds;
            return (utcEpoch + OfficeOffset + daylightSavingsOffset);

Essential fucked around with this message at 23:56 on Jul 18, 2016

Inverness
Feb 4, 2009

Fully configurable personal assistant.

Combat Pretzel posted:

This UWP and XAML stuff certainly makes it way easier than before, tho. But hey, instead of a common toolkit, that'd ideally be also available to the third party developer, every system app implements the variety of UI elements on their own and always slightly different in look and/or functionality.
I think I remember a presentation about how they'd been working on fixing that for Windows 10.

Did they not make these things available to users? :v:

WorkerThread
Feb 15, 2012

I'm a stupid idiot baby and struggling to understand configuration in Asp.Net Core.

My company's leadership has finally bought into the idea that we don't need to do new development in the .Net 2.0 web site style, so I'm evaluating how to join this decade while maintaining as much compatibility as possible with our existing sites. Having the existing auth cookie (FormsAuthentication) work in both old and new sites is pretty critical. Even though I'm destroying some of the hard work from the Asp.Net team by including System.Web, I need access to FormsAuthenticationTicket so I can plug that into the Asp.Net Core cookie authentication system.

The trouble is, I need to plug in the decryption and validation keys for our web farm but since new Asp.Net projects don't use web.config, I don't know where or how to configure that (I tested by setting the machineKey stuff in my machine.config, but I'm guessing that's a bad strategy for production). The new Data Protection APIs seem to make it pretty clear that our existing practices are not supported.

My question is, how config work? What can I do to enable this scenario? One of the other issues is that a bunch of our internal libs use EnterpriseLibrary.Data, which picks up connection strings from app/web.config and System.Configuration, and while I've tested manually replacing the EnterpriseLibrary container with custom configuration at run-time, it would be much nicer just to have a "Connection Strings" config section like in the existing fat framework.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Essential posted:

A bunch of date code

C# code:
var tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var startDate = new DateTimeOffset(2016, 1, 1, 0, 0, 0, tz.BaseUtcOffset);
Console.WriteLine(startDate.ToUnixTimeSeconds()); //4.6

var startDateInPST = TimeZoneInfo.ConvertTime(startDate, tz);
var manual = startDateInPST - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
Console.WriteLine("Manual={0}", manual.TotalSeconds);

Console.ReadKey();
This worked for me

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!

Inverness posted:

I think I remember a presentation about how they'd been working on fixing that for Windows 10.

Did they not make these things available to users? :v:
I don't know, I've only started coding a little again after like two years of abstinence. Their applications currently don't indicate an existence of a common toolkit, tho. Maybe there may be results when the update hits in August.

Essential
Aug 14, 2003

gariig posted:

C# code:
var tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var startDate = new DateTimeOffset(2016, 1, 1, 0, 0, 0, tz.BaseUtcOffset);
Console.WriteLine(startDate.ToUnixTimeSeconds()); //4.6

var startDateInPST = TimeZoneInfo.ConvertTime(startDate, tz);
var manual = startDateInPST - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
Console.WriteLine("Manual={0}", manual.TotalSeconds);

Console.ReadKey();
This worked for me

Thank you SO much! I knew it was much simpler than I was making it. Seriously I can't tell you how much I appreciate your help! The only thing I had to add was a DST check to subtract 1 hour (due to the end result using GMT time zone).

Red Mike
Jul 11, 2011

ljw1004 posted:

Red Mike, my team at Microsoft is the one dealing with adoption and migration of .NET and .NET Core. If you'd like to run over your handy list with us, or discuss in more depth, send me an email at lwischik@microsoft.com. Same goes for anyone else of course.

Thanks! I'll be sure to run it by you once I've got time to actually finish it. The way it's looking, it seems to be a pretty definite no-go for the near future even ignoring library issues, but some discussion with people who properly know the system would definitely help.

Slightly relating to this, I've once again had the fun chance to diagnose bugs with Entity Framework interactions with Mysql/Connector. That's now one definite bug and a potential bug we've had to investigate down to source code for both libraries, each causing us to have twice the amount of code needed everywhere in order to make a server actually be remotely stable. :v:

john donne
Apr 10, 2016

All suitors of all sorts themselves enthral;

So on his back lies this whale wantoning,

And in his gulf-like throat, sucks everything

That passeth near.
I want to use .NET Core for a new greenfield application. Convince me not to, please.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
Xamarin Previews of iOS 10, tvOS 10, watchOS 3 and macOS support was released yesterday. I'm really liking the watchOS 3 support, which is much better than 2. It had major issues with native builds. This time around it's gotten better at actually running on native hardware. So that's sweet.

Go on and check um' out :).

Gul Banana
Nov 28, 2003

posts like https://blogs.windows.com/buildingapps/2016/07/14/choosing-the-path-forward-for-existing-desktop-apps-4/#6g8pOSTmjQDXq5GL.99 make me wistful- it sure would be nice to be using the tech Microsoft is actively supporting, improving, etc
but it's just so irrelevant. who uses desktop apps? businesses. and what do businesses not do quickly? upgrade operating systems. UWP is totally off the table for years to come.

the way .net core was rolled out is much better, as a new model that runs everywhere the old one did and more. once again, the web-app world continues to evolve while rich-client is left behind..

amotea
Mar 23, 2008
Grimey Drawer

Gul Banana posted:

posts like https://blogs.windows.com/buildingapps/2016/07/14/choosing-the-path-forward-for-existing-desktop-apps-4/#6g8pOSTmjQDXq5GL.99 make me wistful- it sure would be nice to be using the tech Microsoft is actively supporting, improving, etc

I can't figure out what we as developers are supposed to get out of this... we have to jump through a metric poo poo ton of hoops to get our perfectly working desktop apps to become a UWP package or something? WPF applications run just fine on Windows 10 lol. Are they implying people want to run our boring industrial business app on their xbox?

mystes
May 31, 2006

amotea posted:

I can't figure out what we as developers are supposed to get out of this... we have to jump through a metric poo poo ton of hoops to get our perfectly working desktop apps to become a UWP package or something? WPF applications run just fine on Windows 10 lol. Are they implying people want to run our boring industrial business app on their xbox?
But how will you get users for your boring industrial business app if your customer's procurement department can't find it in the app store?!

ljw1004
Jan 18, 2005

rum

amotea posted:

I can't figure out what we as developers are supposed to get out of this... we have to jump through a metric poo poo ton of hoops to get our perfectly working desktop apps to become a UWP package or something? WPF applications run just fine on Windows 10 lol. Are they implying people want to run our boring industrial business app on their xbox?

It's not a lot of hoops :(

Another audience is people who sell their Windows software direct from their websites, but would also like to be able to offer it on the App Store -- might make an easier experience or attract new customers. For instance, I'd love to be able to get Camtasia and .NET Reflector and Paint.NET through the store -- all of them apps that I waste time installing on each new machine, that I have to go through hoops to find them on their websites and retrieve my license keys. If the machine knew that I already owned them, and could install them with a single click, I'd be happy.

Gul Banana
Nov 28, 2003

that totally would be convenient! but again, from the perspective of the creators of camtasia - most of your customers are not using windows 10, so the idea of spending a bunch of effort to convert the app to something that only works on win10 is just going to be dismissed out of hand

amotea
Mar 23, 2008
Grimey Drawer

Gul Banana posted:

that totally would be convenient! but again, from the perspective of the creators of camtasia - most of your customers are not using windows 10, so the idea of spending a bunch of effort to convert the app to something that only works on win10 is just going to be dismissed out of hand

Yeah this, I get what ljw1004 is saying though, I hate having to install 20 tiny apps after every format.

But why does everything have to become UWP... some hybrid would have been better, maybe the store should be able to do silent installs of existing .MSI packages or something? Meh it probably wouldn't work for apps with the advanced setup settings and all.

The main problem for me (and I think a lot of devs) with all the new MS technologies is that there's a 50% chance they'll be abandoned within the next 2 years, and they're not fundamentally better than what we already have. They're just shiny and match the vision of current MS management.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

amotea posted:

But why does everything have to become UWP... some hybrid would have been better, maybe the store should be able to do silent installs of existing .MSI packages or something? Meh it probably wouldn't work for apps with the advanced setup settings and all.
Isn't that what Project Centennial is for? It converts an MSI to the APPX format.

Also, the anniversary update is adding extension support to the API for use by Edge. I imagine that could be used for an optional add-on thing.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

amotea posted:

But why does everything have to become UWP...

Not everything does. Like how you don't have to use the Mac App Store to download programs on macOS, but it can be very helpful for the same reasons as what MS is trying to do with the Windows Store.


Inverness posted:

Isn't that what Project Centennial is for? It converts an MSI to the APPX format.

Also, the anniversary update is adding extension support to the API for use by Edge. I imagine that could be used for an optional add-on thing.

The Anniversary update also has an APPX installer built in now, so you can just double click on them to sideload them. Sideloading is also enabled by default too, so users have to opt out of it being enabled.

amotea
Mar 23, 2008
Grimey Drawer

Drastic Actions posted:

Not everything does. Like how you don't have to use the Mac App Store to download programs on macOS, but it can be very helpful for the same reasons as what MS is trying to do with the Windows Store.

True, except that older tech (WPF) was abandoned in favor of this stuff.

Gul Banana
Nov 28, 2003

yeah if this was like.. "wpf 2.0: now if you run it on windows 10 it gets touch apis and live tiles edition" that would have been extremely acceptable

Inverness
Feb 4, 2009

Fully configurable personal assistant.
I assume part of this situation is due to infighting at Microsoft that is probably only recently starting to subside.

Gul Banana
Nov 28, 2003

i wouldn't be too quick to assume actual ill will when it's just, a very large organisation which is trying to do many things at once vOv
easy to get conflicting priorities and false starts in that environment

TheBlackVegetable
Oct 29, 2006

amotea posted:

True, except that older tech (WPF) was abandoned in favor of this stuff.

So, I'm going to start development soon on a windows desktop app, and I was going to use WPF. It needs to run Win7/8, WPF is still the best option, right?

GameCube
Nov 21, 2006

Hello. Here is a snippet of a unit test that is not doing what I want it to do.
code:
    int nextIndex = 0;
    Func<LomarfType, int, int, Action> actionGenerator = (lomarf, index, delay) => async () =>
    {
        await queue.WaitAsync(lomarf);
        // WaitAsync should only return when it's our turn
        Assert.Equal(nextIndex, index);
        // simulate execution
        await Task.Delay(delay * 1000);
        // increment the index counter before dequeuing, which will signal the next waiter
        nextIndex++;
        queue.DequeueLomarf(lomarf);
    };
    
    var tasks = Enumerable.Range(0, delays.Length).Select(x => Task.Factory.StartNew(actionGenerator(lomarfs[x], x, delays[x]))).ToArray();
    
    // execute all tasks simultaneously
    Task.WaitAll(tasks);
    Assert.Equal(nextIndex, delays.Length);
My problem is that Task.WaitAll is returning before all the tasks have finished. Please help me figure out why the gently caress that is happening. Thank you.

Inverness
Feb 4, 2009

Fully configurable personal assistant.
WPF isn't dead, but it's certainly not a big development priority anymore.

I expect that the increasing popularity of .NET might change things there.

IIRC there was someone in this thread from the team talking about the improvements they wanted to make to it.

Edit:

GameCube posted:

Hello. Here is a snippet of a unit test that is not doing what I want it to do.
code:
    int nextIndex = 0;
    Func<LomarfType, int, int, Action> actionGenerator = (lomarf, index, delay) => async () =>
    {
        await queue.WaitAsync(lomarf);
        // WaitAsync should only return when it's our turn
        Assert.Equal(nextIndex, index);
        // simulate execution
        await Task.Delay(delay * 1000);
        // increment the index counter before dequeuing, which will signal the next waiter
        nextIndex++;
        queue.DequeueLomarf(lomarf);
    };
    
    var tasks = Enumerable.Range(0, delays.Length).Select(x => Task.Factory.StartNew(actionGenerator(lomarfs[x], x, delays[x]))).ToArray();
    
    // execute all tasks simultaneously
    Task.WaitAll(tasks);
    Assert.Equal(nextIndex, delays.Length);
My problem is that Task.WaitAll is returning before all the tasks have finished. Please help me figure out why the gently caress that is happening. Thank you.
Your generated actions will complete immediately because they're the equivalent of an async void method which prevents the caller from awaiting them.

What you need to do is have your actionGenerator return a Task that can be awaited instead of starting a new task.

I'm not sure about the async lambda syntax off of the top of my head, but this should be something like what would work:
code:
    int nextIndex = 0;
    Func<LomarfType, int, int, Task> actionGenerator = async (lomarf, index, delay) =>
    {
        await queue.WaitAsync(lomarf);
        // WaitAsync should only return when it's our turn
        Assert.Equal(nextIndex, index);
        // simulate execution
        await Task.Delay(delay * 1000);
        // increment the index counter before dequeuing, which will signal the next waiter
        nextIndex++;
        queue.DequeueLomarf(lomarf);
    };
    
    Task[] tasks = Enumerable.Range(0, delays.Length).Select(x => actionGenerator(lomarfs[x], x, delays[x])).ToArray();

    Task.WaitAll(tasks);

Inverness fucked around with this message at 21:05 on Jul 21, 2016

GameCube
Nov 21, 2006

Inverness posted:

Your generated actions will complete immediately because they're the equivalent of an async void method which prevents the caller from awaiting them.

What you need to do is have your actionGenerator return a Task that can be awaited instead of starting a new task:

I vaguely remembered reading that you should avoid async void, but I didn't remember why. That did it, thanks. Here's what I did:
code:
Func<LomarfType, int, int, Task> actionGenerator = (lomarf, index, delay) => Task.Run(async () =>
{
    await queue.WaitAsync(lomarf);
    // we should only return from WaitAsync when it's our turn
    Assert.Equal(nextIndex, index);
    // simulate lomarf execution
    await Task.Delay(delay * 1000);
    // increment the index counter before dequeuing, which will signal the next waiter
    nextIndex++;
    queue.DequeueLomarf(lomarf);
});

var tasks = Enumerable.Range(0, delays.Length).Select(x => actionGenerator(lomarfs[x], x, delays[x])).ToArray();
tasks.WaitAll();

Inverness
Feb 4, 2009

Fully configurable personal assistant.

GameCube posted:

I vaguely remembered reading that you should avoid async void, but I didn't remember why. That did it, thanks. Here's what I did:
code:
Func<LomarfType, int, int, Task> actionGenerator = (lomarf, index, delay) => Task.Run(async () =>
{
    await queue.WaitAsync(lomarf);
    // we should only return from WaitAsync when it's our turn
    Assert.Equal(nextIndex, index);
    // simulate lomarf execution
    await Task.Delay(delay * 1000);
    // increment the index counter before dequeuing, which will signal the next waiter
    nextIndex++;
    queue.DequeueLomarf(lomarf);
});

var tasks = Enumerable.Range(0, delays.Length).Select(x => actionGenerator(lomarfs[x], x, delays[x])).ToArray();
tasks.WaitAll();
I'm confused because it seems like you'd have the same problem where task created with Task.Run() would finish early because the lambda being used to create it is still equivalent to async void.

Edit: It seems Task.Run() accepts delegates that return a task and creates a proxy for that task. That would work then.

Though it seems unnecessary to create a new task like that instead of just awaiting directly like in my edit.

Inverness fucked around with this message at 21:17 on Jul 21, 2016

GameCube
Nov 21, 2006

I'm just new at this and forgot that a function with await in it automatically returns a Task.

Adbot
ADBOT LOVES YOU

Gul Banana
Nov 28, 2003

at least until the next Roslyn release where ljw1004's proposal allows it to return arbitrary awaitables :O

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply