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
ljw1004
Jan 18, 2005

rum

Gravity Pike posted:

I work at a primarily Java/*nix shop, and I've been asked to CR a bunch of .NET/C# code that we've outsourced to a contractor. Does anyone know of an IDE that'll run on OSX and take care of basic stuff like meta-click on methods to find implementations? The code is all windows-logging specific stuff, so there's no chance of it working under mono, but I'd like to at least be able to read the code without booting into a different operating system.

"Visual Studio Code" works on OSX. You'll want the Omnisharp plugin.




(Caveat: I know that VSCode+Omnisharp works on OSX, and I know that the Windows version is picking up GoToRef etc. for traditional .csproj projects, but I don't know if the OSX version will also work with traditional .csproj or solely with .NETCore)

ljw1004 fucked around with this message at 05:33 on Aug 17, 2016

Adbot
ADBOT LOVES YOU

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!

ljw1004 posted:

You have to add a reference to the NuGet package System.Data.SqlClient.

Thanks, that did the trick. It seemed weird to me that something that sounded like a standard library namespace would be in Nuget and not just built-in.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

ljw1004 posted:

(Caveat: I know that VSCode+Omnisharp works on OSX, but I don't know if the OSX version works with traditional .csproj projects or only with the newer .NETCore projects).

VS Code doesn't work with csproj, but Xamarin Studio does.

TheBlackVegetable
Oct 29, 2006

Asymmetrikon posted:

Thanks, that did the trick. It seemed weird to me that something that sounded like a standard library namespace would be in Nuget and not just built-in.

I believe you've always had to reference the assembly (via project -> add references in VS), this way at least it's explicitly packaged in.

Speaking of NuGet, I've started using Paket for package management. It seems to be entirely better than NuGet, does anyone know a reason to use NuGet instead, before I go and change every solution over to Paket?

Gul Banana
Nov 28, 2003

nuget 3 using project.json instead of packages.config works basically the same as paket. with paket I'd also be worried about supporting complex solutions that e.g. mix .net core and .net framework stuff..

Gul Banana
Nov 28, 2003

not that this is flawless with nuget, but for paket it looks like support just isn't done at all:
https://github.com/fsprojects/Paket/pull/1785

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Asymmetrikon posted:

Thanks, that did the trick. It seemed weird to me that something that sounded like a standard library namespace would be in Nuget and not just built-in.

That's the point of .NET Core. Instead of installing a giant framework on every computer that needs to run your app, your app specifies exactly what things it needs and resolves dependencies at compile time and packages the whole thing up. Way more portable.

AWWNAW
Dec 30, 2008

e: disregard, I am dumb.

ljw1004
Jan 18, 2005

rum

Drastic Actions posted:

VS Code doesn't work with csproj, but Xamarin Studio does.

I got clarification from the developer behind Omnisharp:

* VSCode (via omnisharp) will work on ALL platforms, for both .csproj projects and .NETCore projects
* To support .csproj, VSCode needs either msbuild (windows) or Mono (linux/OSX) to be installed. In the later case, Mono's XBuild is used to ingest the .csproj and provide a best effort for IDE tooling.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

ljw1004 posted:

I got clarification from the developer behind Omnisharp:

* VSCode (via omnisharp) will work on ALL platforms, for both .csproj projects and .NETCore projects
* To support .csproj, VSCode needs either msbuild (windows) or Mono (linux/OSX) to be installed. In the later case, Mono's XBuild is used to ingest the .csproj and provide a best effort for IDE tooling.

Ahh, they readded it last month. That's what I get for not checking :doh:

Veth
May 13, 2002
Homeless Pariah
I have this elaborate calcuator we use for design and manufacturing done in WinForms. We need to be able to print off these designs on paper, but the printing routines for this are done such that any minor modifications, like trying to get the picture to be 0.250" lower on the page, are giant pains in the rear end. It's an elaborate system of coordinates and offsets which makes it into a giant avalanche of hosed up any time a change needs to be made.

Is there a better way to be doing printing layouts other than coordinates and offsets? I feel like a template would be a good idea although I'm not sure what to try. I was hoping to find something that would work something like the layout designer in VS but for printing.

I've tried basic HTML, but everyone agrees its too ugly. I've tried printing the screen, but that looks terrible and doesn't allow me to remove things that don't need to printed.

ljw1004
Jan 18, 2005

rum
For fun: I made some short videos showing how "Game of Life" and "Mandelbrot set" work, and how to compute them fast on your GPU.


The code's for a UWP app for Win10 using the Win2d graphics library. I've written it in VB, but it should be easy to do in C#. https://github.com/ljw1004/blog/tree/master/Win2d

https://www.youtube.com/watch?v=KcmXph7pRZI
https://www.youtube.com/watch?v=YGjcWhV5f8s

I get 20fps for the mandlebrot on my $80 Lumia 640 phone!

ModeSix
Mar 14, 2009

I'm in the process of learning .Net Core and I have a question about DbContext.

I'm using an override in my DbContext and want to tell it to use a Postgres SQL server, but the Npgsql documentation is loving wondrously inadequate.

This is what I've got in my WorldContext.cs file:
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace TheWorld.Models
{
    public class WorldContext : DbContext
    {
        private IConfigurationRoot _config;

        public WorldContext(IConfigurationRoot config)
        {
            _config = config;
        }

        public DbSet<Trip> Trips { get; set; }
        public DbSet<Stop> Stops { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);


            optionsBuilder.UseSqlServer(_config[""]); // I don't want to use SQL Server, I want to use PgSQL.
        }

        

    }
}
Here are the Dependencies in my project.json

code:
"dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "Npgsql": "3.1.0-*",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0"
  }
How do I use the Npgsql module to have my override use Npgsql to connect to a Postgres DB as opposed to a regular MSSql server? This is an issue because it will in the end be deployed on Linux and MSSql's fabled Linux port hasn't appeared yet, and I'd like to use the Json features of PGSQL as well.

ModeSix fucked around with this message at 13:02 on Aug 19, 2016

Nth Doctor
Sep 7, 2010

Darkrai used Dream Eater!
It's super effective!


ljw1004 posted:

For fun: I made some short videos showing how "Game of Life" and "Mandelbrot set" work, and how to compute them fast on your GPU.


The code's for a UWP app for Win10 using the Win2d graphics library. I've written it in VB, but it should be easy to do in C#. https://github.com/ljw1004/blog/tree/master/Win2d

https://www.youtube.com/watch?v=KcmXph7pRZI
https://www.youtube.com/watch?v=YGjcWhV5f8s

I get 20fps for the mandlebrot on my $80 Lumia 640 phone!

These are awesome. Everyone should go watch.

mystes
May 31, 2006

From the earlier discussion about combining Windows Forms and WPF, which direction is less horrible? I was trying to do something in a DataGridView in WPF and it was way too slow, so I switched to Windows Forms, but it would also be really convenient to be able to use a WPF RichTextBox so I don't have to deal with RTF or something like that.

Edit: ElementHost is actually OK, right? So I should be able to keep the application as windows forms and just embed the WPF control without too much trouble?

TheBlackVegetable
Oct 29, 2006

mystes posted:

From the earlier discussion about combining Windows Forms and WPF, which direction is less horrible? I was trying to do something in a DataGridView in WPF and it was way too slow, so I switched to Windows Forms, but it would also be really convenient to be able to use a WPF RichTextBox so I don't have to deal with RTF or something like that.

Edit: ElementHost is actually OK, right? So I should be able to keep the application as windows forms and just embed the WPF control without too much trouble?

ElementHost is working well for me in a legacy Winforms app with new screens and controls in WPF

Freaksaus
Jun 13, 2007

Grimey Drawer
Does anyone here have any exprience with developing software for modern barcode/RFID scanners in .NET? The last time I did any development for that platform was for windows CE 5.0 with .NET 3.5 and a lot seems to have changed in the meantime.

Looking around it seems that the entire CE line has gone through several name changes and the most current one is Windows 10 IoT. Since we're going to make a new program from scratch I'd prefer developing it for the latest OS, but I'm having a hard time finding out if it's even been adopted yet by hardware manufacturers.

mystes
May 31, 2006

If I have one thread writing (only) to an array of integers (I assume this would cause problems with individually heap allocated objects) and one thread reading (only), can I get away with not doing any synchronization if I don't mind the results possibly getting out of date?

If so, if a small amount of the time I want the writing thread to signal the reading thread (via a bufferblock or something) that a value has been updated but do want the value pulled from the array to be up to date, is there anything special I need to do to ensure this?

raminasi
Jan 25, 2005

a last drink with no ice
If you're looking for the lowest-effort solution to whatever your actual problem is, it's a BlockingCollection.

mystes
May 31, 2006

raminasi posted:

If you're looking for the lowest-effort solution to whatever your actual problem is, it's a BlockingCollection.
But I don't want reading the value from the array to block because I need to do that from the GUI thread right as the result is going to be used to change the style of something that's about to be drawn.

I guess I could just set a really low timeout and use a default value in that case, but it just seems like then there's no point in using the blockingcollection. I'm also just curious because I have always carefully avoided threading whenever possible but now I'm interested in how it works.

mystes fucked around with this message at 23:31 on Aug 22, 2016

ljw1004
Jan 18, 2005

rum

mystes posted:

If I have one thread writing (only) to an array of integers (I assume this would cause problems with individually heap allocated objects) and one thread reading (only), can I get away with not doing any synchronization if I don't mind the results possibly getting out of date?

Short answer: Yes.

But you haven't told us the exact correctness guarantee you want. Here's my attempt at fleshing out your requirements:

"If thread X writes an integer to index i of an array, and thread Y reads from that index, then thread Y must retrieve either the old value or the new value. Moreover, once Y has started to retrieve the new value, subsequent reads on thread Y will still retrieve the new value at least until such time as a new value is written."

That works!

One question is about are "tearing" -- e.g. if you write a four-byte integer, might another thread be able to read the integer and read the first two bytes from the old value and the next two bytes from the new value? No it can't, not if the int is properly aligned. And in an array it will be.

Another question is about "side effects" -- e.g. if you write at index i, might that possibly affect the value at index i+1 ? No it can't.



But the guarantee I wrote above is a pretty small guarantee. Unless you're careful, you won't be able to build a working algorithm out of just that guarantee. Here's a scenario...

1. Array starts with values [0,1,2,3]
2. Thread X writes in a new value for index0: [15,1,2,3]
3. Thread X writes in a new value for index1: [15,27,2,3]
4. Thread Y reads index 1 followed by index 0.

It's possible that thread Y will read the new value "27" of index 1 but then read the old value "0" of index 0 -- even though they were written in reverse order! This scenario is possible, and doesn't contradict the guarantee.


The .NET memory model is documented in the ECMA CLI spec: http://www.ecma-international.org/publications/standards/Ecma-335.htm

Actually, the memory model used by Microsoft's implementations of .NET are a bit stronger (i.e. less bizarre) than the minimum mandated by ECMA. But I don't know the details.


CAVEAT: This isn't my area. I've always found it confusing and baffling. I'm just trying to answer as best I can :)

mystes
May 31, 2006

ljw1004 posted:

Short answer: Yes.

But you haven't told us the exact correctness guarantee you want. Here's my attempt at fleshing out your requirements:

"If thread X writes an integer to index i of an array, and thread Y reads from that index, then thread Y must retrieve either the old value or the new value. Moreover, once Y has started to retrieve the new value, subsequent reads on thread Y will still retrieve the new value at least until such time as a new value is written."

That works!

One question is about are "tearing" -- e.g. if you write a four-byte integer, might another thread be able to read the integer and read the first two bytes from the old value and the next two bytes from the new value? No it can't, not if the int is properly aligned. And in an array it will be.

Another question is about "side effects" -- e.g. if you write at index i, might that possibly affect the value at index i+1 ? No it can't.



But the guarantee I wrote above is a pretty small guarantee. Unless you're careful, you won't be able to build a working algorithm out of just that guarantee. Here's a scenario...

1. Array starts with values [0,1,2,3]
2. Thread X writes in a new value for index0: [15,1,2,3]
3. Thread X writes in a new value for index1: [15,27,2,3]
4. Thread Y reads index 1 followed by index 0.

It's possible that thread Y will read the new value "27" of index 1 but then read the old value "0" of index 0 -- even though they were written in reverse order! This scenario is possible, and doesn't contradict the guarantee.


The .NET memory model is documented in the ECMA CLI spec: http://www.ecma-international.org/publications/standards/Ecma-335.htm

Actually, the memory model used by Microsoft's implementations of .NET are a bit stronger (i.e. less bizarre) than the minimum mandated by ECMA. But I don't know the details.


CAVEAT: This isn't my area. I've always found it confusing and baffling. I'm just trying to answer as best I can :)
Thanks! Your summary of my requirements is exactly what I was trying to say and I don't need any consistency guarantees, so the scenario you described shouldn't be a problem.

Severed
Jul 9, 2001

idspispopd
I have about a 200-level knowledge of C#, mostly from a WPF perspective. I'd like to get started in ASP.Net MVC. Considering that I have an intermediate background in C#, what would be some good resources to consume to get started? I typically prefer books (I usually mark them up a ton and take notes) but would be open to websites as well. I don't want to spend a ton of time on the basics of C#, and most of the books I've looked at dedicate quite a bit to that before getting into the new bits.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
C# in Depth gets down into the details of the more advanced parts of C# (generics, lambdas/expression trees, async/await) and is a very good read overall.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Bognar posted:

C# in Depth gets down into the details of the more advanced parts of C# (generics, lambdas/expression trees, async/await) and is a very good read overall.

This thing is so hyped up and then I finally read it and was disappointed. It's well presented and all, but it's mostly things that will have occurred to you if you've been working in C# long enough. Or at least that's how I remember it.

Night Shade
Jan 13, 2013

Old School

RICHUNCLEPENNYBAGS posted:

This thing is so hyped up and then I finally read it and was disappointed. It's well presented and all, but it's mostly things that will have occurred to you if you've been working in C# long enough. Or at least that's how I remember it.

This should be true of any language that isn't horribly convoluted and esoteric, but that doesn't mean the book is a bad resource for people who haven't spent forever writing C#. You just aren't its target audience.

SeXTcube
Jan 1, 2009

I'm starting a job working with C# (and VB lol) in a few weeks and C# in Depth has been a great read for me.

Mister Duck
Oct 10, 2006
Fuck the goose
Doing some digging lately into SyncFlush errors coming from the WPF graphics stack. SyncFlush is basically a broad container for various errors that occur during rendering, aggregate in the graphics stack, and show up at some point later in program execution (hence the sync).

I was wondering a few things:

1) Has anyone here seen instances of SyncFlush issues lately (we're talking 4.6 and above installed and an application targeting 4.0+)?
2) If so, can you possibly describe any "edge" type scenarios you are using?

Specifically things that are not the most straightforward way of using WPF like:

1) Multi-threaded visuals using HostVisual
2) Cross AppDomain or Process visuals isolated using MAF
3) Heavy interop with Winforms or other custom things using HwndHost

Most of these errors are spurious, so trying to nail down some reproduction scenarios is difficult. So if anyone has seen these, please let me know, I can try to incorporate any scenarios into my testing and maybe fix a bug or two that has annoyed you.

Thanks!

Mister Duck fucked around with this message at 15:41 on Aug 25, 2016

amotea
Mar 23, 2008
Grimey Drawer
We've had OutOfMemoryExceptions popping up out of SyncFlush() when displaying a BitmapImage in an Image control. The problem IIRC was that the GC didn't kick in in time when swapping images because it didn't track the unmanaged memory.

So the user would e.g. swap the image in the Image control a few times, thereby raising the unmanaged memory usage with a few hundred MB (high res images), but the GC didn't release the old native handles because managed memory was still low. We "fixed" this by just calling the GC manually like so in tactical spots:
code:
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Artificially raising managed memory consumption using GC.AddMemoryPressure didn't really seem to help at the time.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

amotea posted:

We've had OutOfMemoryExceptions popping up out of SyncFlush() when displaying a BitmapImage in an Image control. The problem IIRC was that the GC didn't kick in in time when swapping images because it didn't track the unmanaged memory.

So the user would e.g. swap the image in the Image control a few times, thereby raising the unmanaged memory usage with a few hundred MB (high res images), but the GC didn't release the old native handles because managed memory was still low. We "fixed" this by just calling the GC manually like so in tactical spots:
code:
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Artificially raising managed memory consumption using GC.AddMemoryPressure didn't really seem to help at the time.

Why aren't you disposing the Image objects? That should clean up the unmanaged memory. calling GC.Collect() is almost always a bad thing.

Calidus
Oct 31, 2011

Stand back I'm going to try science!
Is there some fancy way to mark a variable as DEPRECATED and throw a warnings when it is used in VS?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Calidus posted:

Is there some fancy way to mark a variable as DEPRECATED and throw a warnings when it is used in VS?

The use of the word "variable" is weird here. If you mean, "a local variable within a method", no, and why would you? If it's not being used or shouldn't be used, just remove it. It doesn't represent the public API of your class in any way.

For everything else:
[Obsolete]

Calidus
Oct 31, 2011

Stand back I'm going to try science!
I need to keep a the variable property around to keep my application backwards compatible with older serialized objects.

edit: ObsoleteAttribute looks like what I want

Calidus fucked around with this message at 19:08 on Aug 25, 2016

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
If you haven't seen it yet, here's the list of potential C# 7 features.

https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/

Inverness
Feb 4, 2009

Fully configurable personal assistant.

mystes posted:

From the earlier discussion about combining Windows Forms and WPF, which direction is less horrible? I was trying to do something in a DataGridView in WPF and it was way too slow, so I switched to Windows Forms, but it would also be really convenient to be able to use a WPF RichTextBox so I don't have to deal with RTF or something like that.

Edit: ElementHost is actually OK, right? So I should be able to keep the application as windows forms and just embed the WPF control without too much trouble?
I'd like to know more about your DataGridView issue. Were you using row virtualization?

9-Volt Assault
Jan 27, 2007

Beter twee tetten in de hand dan tien op de vlucht.

Bognar posted:

If you haven't seen it yet, here's the list of potential C# 7 features.

https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/

MIcrosoft should promote F# instead of trying to turn C# into a worse F#.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

Bognar posted:

If you haven't seen it yet, here's the list of potential C# 7 features.

https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/
I wish I knew what they were thinking by not including code generators in C# 7.

That would have a bigger impact on my code than anything else. I've wanted a simpler AOP solution for awhile.

I also wanted a way to easily generate record classes by just looking at an attribute on a simple class or struct.

ljw1004
Jan 18, 2005

rum

Inverness posted:

I wish I knew what they were thinking by not including code generators in C# 7.

We can't do everything that we want! I think the problem was that two other unexpected areas came up which took priority over generators -- too many incoming bugs being filed, and user feedback that we needed to reduce VS memory use so it runs faster and is more stable even with large projects and even with Resharper.

smarion2
Apr 22, 2010
I feel like I'm never excited for these updates because none of it ever applies to me. I see myself using the basic features of c# 99% of the time. Is this because I've never really made anything that complicated? Would I do good for myself learning Linq or async await and forcing myself to use them in my apps? The tuples look interesting because I specifically remember wanting to return more than one value at one point in time but figured out a way to not need to (because I didn't know how)

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



smarion2 posted:

I feel like I'm never excited for these updates because none of it ever applies to me. I see myself using the basic features of c# 99% of the time. Is this because I've never really made anything that complicated? Would I do good for myself learning Linq or async await and forcing myself to use them in my apps? The tuples look interesting because I specifically remember wanting to return more than one value at one point in time but figured out a way to not need to (because I didn't know how)

Linq is really good and I miss the hell out of it when I use other languages.

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