|
In that example, I cannot modify Foo. I need to use it's public event to listen for completion.
|
# ? Feb 27, 2019 22:42 |
|
|
# ? Jun 8, 2024 08:27 |
|
Potassium Problems posted:other devs Luckily for me, there are no other devs I’m not a developer, I’m a firewall engineer writing tools that help me streamline my daily grind. I implement IEquatable<T> when an object has a unique identifier of some sort, be it a UUID/Guid or identity key. I implement IComparable<T> when a class has an obvious sort field, like Name, or Description. The only time I’ve done anything “clever” (in the pejorative sense) is my Time class, which freely converts to/from double where, for instance, 12:30 pm can be represented as 12.5 I understand what you guys are saying, and I don’t discount it, but as yet (knock on wood) I’ve yet to suffer any adverse effects from doing it this way, and (IMO) the code reads cleaner.
|
# ? Feb 28, 2019 01:24 |
|
User0015 posted:Phone posting here, but what happens to events when a using statement completes? For example foo holds a reference to the SomeHandler action delegate, not the other way around, so foo will get GCd
|
# ? Feb 28, 2019 02:09 |
|
LongSack posted:Luckily for me, there are no other devs I’m not a developer, I’m a firewall engineer writing tools that help me streamline my daily grind. Yo try working with other developers and see how that works for you. I'd loving never overload an operator unless a gun were pointed to my head in a commercial environment.
|
# ? Feb 28, 2019 02:10 |
|
LongSack posted:The only time I’ve done anything “clever” (in the pejorative sense) is my Time class, which freely converts to/from double where, for instance, 12:30 pm can be represented as 12.5 even ignoring the comparison thing, you will heavily regret writing any time implementation yourself the second you have to deal with anything other than static time stamps if you have any logic surrounding time don't even use the .NET DateTime types, just use NodaTime LongSack posted:and (IMO) the code reads cleaner. less text =/= cleaner code
|
# ? Feb 28, 2019 02:18 |
|
if all of your code is basically just scripts for your own productivity and you know all the implementation details in your head than it's probably fine, but don't mistake abstraction for making things cleaner
|
# ? Feb 28, 2019 02:24 |
|
ThePeavstenator posted:...you will heavily regret writing any time implementation yourself... Yes, this.
|
# ? Feb 28, 2019 02:52 |
|
Bruegels Fuckbooks posted:Yo try working with other developers and see how that works for you. I'd loving never overload an operator unless a gun were pointed to my head in a commercial environment. My rule of thumb for operator overloading: can this class be described as "a wrapper around a single primitive value"? If yes, then overload operators so that they behave the same as the primitive. Otherwise, don't overload them. Eg. let's say you have a Weight class that wraps around the raw decimal value and adds unit-of-measure conversion, tare, precision, maybe timestamps. Then it's intuitive what Weight1 > Weight2 means. But now let's say you have a ProductWeight class that wraps the combination of the product being weighted and the weight itself: at this point someone might expect AppleWeight1 > OrangeWeight2 to ignore the product and just compare weights, while others might expect it to only compare if the product is the same and otherwise throw ArgumentException, so it's better not to provide operators.
|
# ? Feb 28, 2019 11:56 |
|
NihilCredo posted:My rule of thumb for operator overloading: can this class be described as "a wrapper around a single primitive value"? If yes, then overload operators so that they behave the same as the primitive. Otherwise, don't overload them. At least in my experience, that kind of thinking will teach you that your coworkers either a) don't understand the commutative property, order of operations, or where the code for the operator is, or b) will point out that you've screwed up something in your implementation that relies on these intuitions. Method calls are relatively idiot-proof.
|
# ? Feb 28, 2019 13:20 |
|
User0015 posted:Phone posting here, but what happens to events when a using statement completes? For example There being an event is orthogonal to the using statement. All using does is ensure that Dispose is called at the end of the block. If your Dispose interacts with your event, then it will matter; otherwise, it won't. The other part of your question ("How do events relate to object lifetimes?") is a good one. Here, foo will maintain a reference to SomeHandler (that's how it knows what to call!), so SomeHandler won't be GCed until foo is.
|
# ? Feb 28, 2019 16:53 |
|
Maybe wrong thread but does anyone have any advice on finding a host for a few very small Umbraco sites? I'm building a few small projects just to pad out my portfolio and hopefully get a job, and I want to host them somewhere as cheaply as possible (but still perform relatively well on the off chance they start generating traffic). Azure and Umbraco cloud are too expensive (although it's hard to tell with Azure, it's like everything is either free or hugely expensive). I'm being tempted by crappy shared hosting plans that are incredibly cheap and promising the world, but I imagine performance will be terrible... Am I asking for trouble if I try and manage my own VPS? I've managed a few linux servers but never windows...
|
# ? Mar 5, 2019 15:28 |
|
fuf posted:Maybe wrong thread but does anyone have any advice on finding a host for a few very small Umbraco sites? One of my freelance clients uses this place to host his small .NET apps: https://www.smarterasp.net/ I hate working with them but it's because I'm spoiled by Azure. My client loves them. But if you have access to .NET Dev Essentials, or BizSpark, or whatever it's called, you get $150/mo in free Azure credits, and that goes a long way for small non-enterprise hosting. I use that for my personal stuff.
|
# ? Mar 5, 2019 22:54 |
|
Careful Drums posted:But if you have access to .NET Dev Essentials, or BizSpark, or whatever it's called, you get $150/mo in free Azure credits, and that goes a long way for small non-enterprise hosting. I use that for my personal stuff. Hmm thanks for the tip. I don't see the 150/mo thing, just an initial free credit of 150 and then "free services" for 12 months. But again it's kind of unclear. I think I'll give Azure a go. Even if I end up having to move somewhere else it will still be a learning experience.
|
# ? Mar 6, 2019 11:34 |
|
https://appharbor.com/pricing has a free tier and their actually paid plans are pretty simple to understand.
|
# ? Mar 6, 2019 15:17 |
|
I have an async/await question. A long time ago, back in the WebClient, pre-async/await days, the following RetryAction class was created: C# code:
C# code:
pre:3/7/2019 12:44:15 PM sending 3/7/2019 12:44:15 PM error: The remote name could not be resolved: 'some-unresponsive-url.com' 3/7/2019 12:44:20 PM sending 3/7/2019 12:44:20 PM error: The remote name could not be resolved: 'some-unresponsive-url.com' 3/7/2019 12:44:25 PM sending 3/7/2019 12:44:25 PM error: The remote name could not be resolved: 'some-unresponsive-url.com' Fast forward to the HttpClient days, where everything is awaitable and methods are postfixed with "Async". Here's what the usage might look like: C# code:
Here's what we'd see in the log: pre:3/7/2019 12:51:50 PM sending 3/7/2019 12:51:50 PM error: An error occurred while sending the request. Is there something in .NET that accomplishes this already? How would I modify RetryAction to be async/await friendly? Could it be done in such a way that I could indeed get back the exception after the last retry?
|
# ? Mar 7, 2019 19:03 |
|
epalm posted:I have an async/await question.
|
# ? Mar 7, 2019 21:41 |
|
You can't use Actions, you have to use Func<Task>. This is from memory but I've used something similar to this before:code:
|
# ? Mar 7, 2019 22:29 |
|
Nth Doctor posted:Are you able to use third party packages? Because Polly is great for this. Yes, Polly is amazing and you should definitely use it instead of rolling your own async retry and circuit breaker mechanisms.
|
# ? Mar 8, 2019 04:37 |
|
Using a well-established framework such as Polly is probably the best way to solve that problem. But I'm curious. How would you go about writing that asynchronously? Without doing a bunch of homework, I don't know.
|
# ? Mar 8, 2019 18:28 |
|
Is there a way to get timings on all events that occur on a pageload? I've got an ASPX page I'm diagnosing that has a 26s "waiting" time in Chrome inspector before any payload reaches the browser. This isn't surprising, because it has sub-tabs on it that each load up with like, Address Info, Order History, etc etc. The thing is, so many things are loading I can't really step through all of them see. What I was hoping is I could just turn something on during the debug, VS records how long each thing takes, then I could stop it, and examine what the longest running events are. The events already get listed in the Diagnostic Tools > Events section, but there's no timings attached to them, just "Thing 1 happened\nThing 2 happened". I think what I'd like is the Delta between Thing 1 and Thing 2. This happens when you're F10ing through the code with that little x ms popup, but I was hoping to have it harvest/record automatically. Apologies if this is a basic question, I'm really more of a server guy, and really not much of a VS guy. If you're wondering why such a guy is even looking at this, it's a little self improvement project I've taken on to track down some of these more involved complaints and get them more codified before handing them off to a real programmer.
|
# ? Mar 8, 2019 22:32 |
|
Scaramouche posted:Is there a way to get timings on all events that occur on a pageload? I've got an ASPX page I'm diagnosing that has a 26s "waiting" time in Chrome inspector before any payload reaches the browser. This isn't surprising, because it has sub-tabs on it that each load up with like, Address Info, Order History, etc etc. The thing is, so many things are loading I can't really step through all of them see. What I was hoping is I could just turn something on during the debug, VS records how long each thing takes, then I could stop it, and examine what the longest running events are. https://docs.microsoft.com/en-us/visualstudio/profiling/?view=vs-2017
|
# ? Mar 8, 2019 22:35 |
|
Careful Drums posted:Using a well-established framework such as Polly is probably the best way to solve that problem. I'm not sure what you mean, but you can have a async execution on a retry policy: https://github.com/App-vNext/Polly/wiki/Retry https://github.com/App-vNext/Polly#asynchronous-support When you run out of retries, the last exception is thrown out of your ExecuteAsync() call. Here's something I threw together in LINQPad: code:
quote:Caught exception of type System.Exception: "First failure" on try 1. Will retry.
|
# ? Mar 8, 2019 23:07 |
|
FFS it was there already, but the event profiler was default docked to right, the Time/Duration/Thread columns were invisible off to the right, and when it's docked it doesn't let you scroll the display.
|
# ? Mar 9, 2019 03:04 |
|
I've got a weird loving WPF problem with a combobox.. On some user machines (but not all!) clicking the combobox to drop the menu down works fine, but then clicking on a menu item doesn't select it; it's like the click is ignored. You can do the selection fine using the arrow keys, and you can actually click and drag on the combobox like an old-style menu, but click, move pointer, click doesn't work. (You can even do weird poo poo like mouse down, drag menu open, highlight target selection, drag mouse off of menu, click to close menu without changing selection, click menu again, move pointer to item you highlighted before but didn't select, and then click, and that will work.) I've attached some event handlers to see what events are being fired, and it looks like PreviewMouseUp doesn't happen in the broken case, but it does in the working case. The WPF form is inside a WindowsFormsHost which is in turn somehow rendered by the 3d modeler hosting the plugin I'm writing for it, so there's plenty of potential for shenanigans, but I'm totally out of ideas for actually fixing this or even diagnosing it.
|
# ? Mar 9, 2019 21:04 |
|
epalm posted:OK, now you're all caught up. I'm looking at creating a RetryActionAsync class, that has the same or similar functionality. I want to specify how many times to retry, how long to wait between retries, and pass an anonymous action to perform. You should generally avoid defining async void methods because their exception handling does not behave the way you expect: http://www.informit.com/articles/article.aspx?p=2832590&seqNum=2 And you should probably use Task.Run instead of Task.Factory.StartNew because the latter does not play well with async: https://devblogs.microsoft.com/pfxteam/task-run-vs-task-factory-startnew/ I think you can fix your problem by 1) changing Action to Func<Task>, 2) awaiting the call to the action, and 3) replacing Task.Factory.StartNew with Task.Run. Or find a library that does this all for you because getting the details right can be tricky.
|
# ? Mar 9, 2019 21:15 |
|
NoDamage posted:The problem is you're passing in an async void lambda as an argument that takes an Action and then invoking the action without awaiting it: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/ There's no need to start a new task at all, the func returns an awaitable task.
|
# ? Mar 9, 2019 22:02 |
|
New Yorp New Yorp posted:There's no need to start a new task at all, the func returns an awaitable task.
|
# ? Mar 10, 2019 03:13 |
|
I'm a bit of a newbie C# programmer (usually I code in Python) and I'm running into some incredible difficulty. I can't tell if this is me loving up something simple, or if the error is miraculously someone else's fault. I'm using FileHelpers to transform lines in a .csv representing airports into simple objects that have properties correlating with each of the columns in the .csv. This is not a problem. The problem comes when I go to validate what's stored in each property before I suck the object into my database - I cannot seem to compare strings Here's a sample line from the .csv (along with the header at the top of the .csv): pre:"id","ident","type","name","latitude_deg","longitude_deg","elevation_ft","continent","iso_country","iso_region","municipality","scheduled_service","gps_code","iata_code","local_code","home_link","wikipedia_link","keywords" 3754,"KORD","large_airport","Chicago O'Hare International Airport",41.9786,-87.9048,672,"NA","US","US-IL","Chicago","yes","KORD","ORD","ORD","https://www.flychicago.com/ohare/home/pages/default.aspx","http://en.wikipedia.org/wiki/O'Hare_International_Airport","CHI, Orchard Place" input: pre:Console.WriteLine(testrecords[6].ident); Console.WriteLine(testrecords[6].ident.GetType()); Console.WriteLine("KORD".GetType()); pre:"KORD" System.String System.String input: pre:Console.WriteLine(testrecords[6].ident == "KORD"); Console.WriteLine(testrecords[6].ident.Equals("KORD")); Console.WriteLine(String.Equals(testrecords[6].ident, "KORD")); Console.WriteLine("KORD".CompareTo(testrecords[6].ident)); Console.WriteLine(String.Compare(testrecords[6].ident, "KORD")); Console.WriteLine(String.Equals(testrecords[6].ident.Trim(), "KORD")); pre:False False False 1 -1 False input: pre:String testString = testrecords[6].ident; Console.WriteLine(testString); Console.WriteLine(testString.Equals("KORD")); Console.WriteLine(testString.Equals(testrecords[6].ident)); Console.WriteLine(testrecords[6].latitude_deg); Console.WriteLine(testrecords[6].latitude_deg == 41.9786); pre:"KORD" False True 41.9786 True As far as I can tell, this is an issue with FileHelpers - I've perused the documentation for it and can't seem to come up with any reason this should happen. I'm not putting it past me not knowing some specific C# horseshit, though - none of my programming friends are C#/.NET users. I've read this fun primer on comparing strings and feel like I'm not loving that up somewhere. It's the library that I picked that's loving up, right? I don't have brain worms, do I?
|
# ? Mar 10, 2019 15:54 |
|
alternative to reading all that poo poo: is there a good library you recommend for parsing .csv files into objects for C#? that might just be more helpful at this point - FileHelpers was the first one I saw on StackOverflow and a friend recommended it to me based on memories of one college class
|
# ? Mar 10, 2019 15:56 |
|
Epsilon Plus posted:alternative to reading all that poo poo: is there a good library you recommend for parsing .csv files into objects for C#? that might just be more helpful at this point - FileHelpers was the first one I saw on StackOverflow and a friend recommended it to me based on memories of one college class I’ve used CsvHelper before, and it’s Generally Fine. But so is FileHelpers - I’ve never encountered anything like what you’ve described. My money’s on some dumb “I was actually compiling the wrong project” error. But I’m phoneposting, so I can’t look in too much detail.
|
# ? Mar 10, 2019 16:11 |
|
I’ve used CsvHelper for years, does the job I need it to do, well enough that I’ve never looked for another library. Nuget: https://www.nuget.org/packages/CsvHelper GitHub: https://github.com/JoshClose/CsvHelper
|
# ? Mar 10, 2019 16:11 |
|
Epsilon Plus posted:As far as I can tell, this is an issue with FileHelpers - I've perused the documentation for it and can't seem to come up with any reason this should happen. I'm not putting it past me not knowing some specific C# horseshit, though - none of my programming friends are C#/.NET users. I've read this fun primer on comparing strings and feel like I'm not loving that up somewhere. It's the library that I picked that's loving up, right? I don't have brain worms, do I? Looks to me like it's the quotes. testrecords[6].ident is "KORD" and you're comparing it to KORD. Those are not the same. They're not even the same length.
|
# ? Mar 10, 2019 16:18 |
|
Star Warrior X posted:Looks to me like it's the quotes. testrecords[6].ident is "KORD" and you're comparing it to KORD. Those are not the same. They're not even the same length. son of a bitch edit: the console output when I print testrecords[6].ident didn't have an extra set of quotes in it so I presumed everything was fine pre:Console.WriteLine(testrecords[6].ident == "\"KORD\""); thank you for saving my sanity death cob for cutie fucked around with this message at 16:30 on Mar 10, 2019 |
# ? Mar 10, 2019 16:28 |
|
I've used FileHelpers in quite a few projects for work. Unless you actually want those double quotes in your properties, you should look into using the FieldQuotedAttribute. You can tell it what your quote character is, if it's always there, sometimes there, etc. based on your file format. I'd assume you probably want to decorate your string properties with code:
|
# ? Mar 10, 2019 17:18 |
|
I'm trying to use some reflection to expose some C# functions in my toy language interpreter. It looks like I should extract a MethodInfo to get to parameter bindings, but it seems clumsy.code:
code:
|
# ? Mar 14, 2019 07:01 |
|
Rocko Bonaparte posted:I'm trying to use some reflection to expose some C# functions in my toy language interpreter. It looks like I should extract a MethodInfo to get to parameter bindings, but it seems clumsy. Other than "That's just how the reflection APIs work" I dunno what to tell you, except you can and should use nameof instead of a magic string code:
|
# ? Mar 14, 2019 07:43 |
|
You can use expressions too:code:
code:
|
# ? Mar 14, 2019 23:15 |
|
Night Shade posted:You can use expressions too: Haha that's some shenanigans! So you're putting a dummy call for it into an AST and then just inspecting the root node to get the method information?
|
# ? Mar 14, 2019 23:46 |
|
Rocko Bonaparte posted:Haha that's some shenanigans! So you're putting a dummy call for it into an AST and then just inspecting the root node to get the method information? Yup. The body is checked by the compiler and it gets handled the same way as if you declared a regular lambda by refactoring tools.
|
# ? Mar 15, 2019 00:10 |
|
|
# ? Jun 8, 2024 08:27 |
|
Epsilon Plus posted:alternative to reading all that poo poo: is there a good library you recommend for parsing .csv files into objects for C#? that might just be more helpful at this point - FileHelpers was the first one I saw on StackOverflow and a friend recommended it to me based on memories of one college class EPPlus
|
# ? Mar 15, 2019 01:44 |