|
I really like what async/await gives you, but I do agree that there are some nasty hidden gotchas. My main complaint is that you're not able to easily call an async method synchronously. Doing that is basically a recipe for deadlocks, but what option do I have if I'm not running in an async ready context (e.g. console app)? This forces most libraries to expose both synchronous and asynchronous method calls which just pollutes their APIs. If calling asynchronous methods synchronously was easy then we could get rid of this silly *Async duplicate method convention and just expose async methods.
|
# ¿ Jun 21, 2014 01:12 |
|
|
# ¿ May 2, 2024 02:55 |
|
Newf posted:Here's a real easy ASP.NET question for everyone. I'm trying to display a list of strings in a ListView, but the examples I'm working from all work from all bind to properties of the bound objects rather than the objects themselves. EG, the //what goes here line is expressed using something like <% #Eval("PropertyX") %>. How do I display the bound object itself (they're just strings!). Should just be able to use <%# Container.DataItem %>
|
# ¿ Jun 27, 2014 17:57 |
|
Don't use a for-loop and don't use Response.Write in your ASPX page. Use another repeater bound to States, instead.
|
# ¿ Jul 9, 2014 20:49 |
|
Newf posted:To follow up on this... The context here is that I'm making a web front-end that interfaces with a windows service which exposes a bunch of controls exposed via [ServiceContract] class and [OperationContract] methods. I'm using svcutil.exe to generate the client class for the webapp. Web Forms is terrible and will almost never end up being the simplest tool for the job. As you already saw, something as simple as adding an <li> element for every item in a list isn't intuitive. The "event" structure of Web Forms is a misguided attempt to make the web like the desktop which ends up making everything inefficient. If there's nothing forcing you to use Web Forms, use MVC. And if you can help it, don't use MVC2. Get the latest VS you can get your hands on and use the latest version of MVC.
|
# ¿ Jul 10, 2014 14:24 |
|
Ciaphas posted:I have data I need to process with record times at nanosecond resolution (specifically, measured in nanoseconds since the start of the year the data was recorded in, stored as uint64). For now I just need to turn it into a human-readable date and time, like 2012 May 28 11:35:58.000045921 (edit: adjustments will need to happen later, but that's not an immediate requirement). I figured at first (being a .NET and C# newbie) that DateTime would be able to do it with some finagling, but I guess from google that it only can store down to the microsecond, chopping off the 921 nanos at the end there. (Apparently they're important. ) (edit: or is it 0.1 microsecond? Anyway still two digits short in that case) DateTime precision only goes down to the 100 nanoseconds. If you just want to use the built-in formatting DateTime formatting options, then I would say to make a class that wraps DateTime (e.g. PreciseDateTime) to delegate .ToString() calls and use whatever level of precision you need.
|
# ¿ Jul 12, 2014 03:21 |
|
SignalR groups might be able to do what you need, but I imagine you would want to handle choosing which client to send updates to yourself. Groups don't scale as well as users do, and I imagine you would have to set up a group for each ticker which users would join if they want subscriptions. With stocks, that means you'd have a ton of groups. You should be able to use the PersistentConnection API to send messages to individual clients. You'll have to manually keep track of who should be receiving updates depending on the data, but this should work better than having the client subscribe to a large number of groups.
|
# ¿ Jul 14, 2014 18:36 |
|
Betjeman posted:You'll need to override Equals I think This is correct. HashSet first checks the hash, then checks for equality using the specified equality comparer (which will most likely be EqualityComparer<T>.Default which uses .Equals()). But yeah, you should probably be using a Dictionary.
|
# ¿ Jul 16, 2014 15:00 |
|
Newf posted:It's really not a complicated issue, and either implementation works, I think. I've left it as it because the Equals override was only a couple of lines and I'd rather not have to wrap my Adds in Try/Catch blocks. Personally, I'd use a Dictionary and check .ContainsKey before insertion, but I don't think there's a functional difference. It just seems more appropriate to me to use a Dictionary when you're working with keys and values.
|
# ¿ Jul 16, 2014 16:31 |
|
It doesn't help that there's no definitive library method for combining hash codes. Tuple<T1, T2> uses this:C# code:
|
# ¿ Jul 16, 2014 16:41 |
|
GrumpyDoctor posted:If I'm inheriting from an abstract class, is there really no way to make one of the overridden properties more accessible without essentially duplicating it? Use the new keyword and make a call to base.SomeMethod? It's still essentially duplication, but you get to keep the same name.
|
# ¿ Jul 16, 2014 20:17 |
|
Ah, if you're implementing an abstract method/property then no you can't change access rights.
|
# ¿ Jul 16, 2014 20:27 |
|
Geisladisk posted:Does anyone have any tips for streamlining Windows Service development? Take all of your interesting code and put it in a separate project, then debug through a console app? This will work if you can test on your dev machine and not have to deploy to a VM.
|
# ¿ Jul 22, 2014 16:09 |
|
I've used predicate builder for a few things and it worked quite nicely, never the full LINQKit though.
|
# ¿ Jul 24, 2014 14:13 |
|
Newf posted:I'd like to know what gets spit out by Path.GetInvalidFileNameChars(). Is there a more reasonable thing for me to do than boot up a new console app and print them to screen? I feel like Visual Studio should have some sort of console that I can type commands like this into. Unfortunately there's not an easily accessible C# REPL yet. You could use the F# interactive console in Visual Studio: code:
|
# ¿ Jul 25, 2014 14:51 |
|
Congratulations, you now know functional programming!
|
# ¿ Jul 25, 2014 15:34 |
|
Chiming in here about the awesomeness of React. It's a breath of fresh air in the poo poo-filled world of frontend JS frameworks. The .NET shop I work at has picked it up for a few things and is absolutely loving it. My biggest gripe, however, is the complete lack of syntax support (even through plugins) in Visual Studio for JSX.
|
# ¿ Jul 28, 2014 14:34 |
|
Volte posted:I'm using it for exactly that and it's basically the best thing ever, as long as you can afford the price tag (or can get the student discount). Definitely look at MvvmCross, and avoid Xamarin.Forms since it is still basically alpha-quality software despite the production status. I'm using Xamarin + MvvmCross on a sizable education-related project right now and I've been really impressed at how well it all works together. If you want to learn MvvmCross, definitely take a look at the N+1 series of videos by the creator/maintainer of the project. Regarding the demo version, I don't really know how capable it is since we just dove in and bought a subscription. So far, though, it's been completely worth it.
|
# ¿ Jul 30, 2014 03:15 |
|
Dietrich posted:You ever finish something really complex and want to throw up your hands and cackle "It's alive!!" the first time it runs? I usually just get worried about which obvious thing I might have screwed up this time.
|
# ¿ Jul 30, 2014 15:49 |
|
quote:The initializer directly initializes the underlying field – it doesn’t go through the setter. For that reason, it is now meaningful to allow getter-only auto-properties: This seems like a halfway solution to what I really want, which is true readonly (as in the access modifier) properties that are settable through the constructor, e.g.: C# code:
|
# ¿ Aug 1, 2014 20:04 |
|
Mr Shiny Pants posted:The new Identity stuff in MVC 5 is complex. We attempted to use it for a recent project, but ultimately we threw it out and rolled our own like we have done for years. I wish MS would get away from trying to provide the "one identity solution to rule them all" and instead just provide sane defaults for password hashing, password requirements, and default functionality for email validation, password resets, and the like.
|
# ¿ Aug 4, 2014 01:10 |
|
Before I go off writing my own C# bindings for Cairo, does anyone know of a half-decent way of generating EPS files in .NET?
|
# ¿ Aug 5, 2014 04:04 |
|
mortarr posted:Does anyone have or know of a .net wrapper for ghostscript, or some other free pdf library? GhostScript.NET: https://github.com/jhabjan/Ghostscript.NET
|
# ¿ Aug 5, 2014 13:38 |
|
Note that if you're dealing with multiple web servers, caching and cache invalidation becomes a harder problem. However, with just one web server you can either use something as simple as static variables (with thread-safe access), or possibly use the built-in ASP.NET caching. See: http://msdn.microsoft.com/en-us/library/vstudio/ms178597%28v=vs.100%29.aspx http://msdn.microsoft.com/en-us/library/vstudio/18c1wd61%28v=vs.100%29.aspx
|
# ¿ Aug 6, 2014 19:56 |
|
Dr. Poz posted:Mvc Question Use int? and check for nulls. Optionally, if you just want to send them to a custom error page without any special message, use the <customErrors> tag with a redirect in the web.config.
|
# ¿ Aug 6, 2014 20:42 |
|
Sounds very similar to Event Sourcing to me. Changes to the model are described as events, and those events are applied in order. Events can be written to a database or queue extremely quickly and then processed separately. The end result is high scalability at the expense of immediate updates. You probably won't find too many libraries for this since the events are highly specific to your domain model. Also, for the vast majority of the time you can get away with simple CRUD anyway.
|
# ¿ Aug 7, 2014 19:16 |
|
gariig posted:InitClass will be called at startup because the runtime wants to create the variable initialized. It sounds like you want Lazy<T>. Without a better sample it's hard to say if this is good or bad. I'd lean toward not doing it because it's hard to mock out or hide static anything during a unit test. Jon Skeet has a useful post on static variables and initialization: http://csharpindepth.com/Articles/General/Beforefieldinit.aspx Long story short, if you really want to continue using statics to do a lazy check, add a static constructor and initialize your variable there. In general, though, it's better to not try to rely on edge case scenarios of the CLR for lazy loading and just implement it yourself. Use Lazy<T> or maybe something like: C# code:
|
# ¿ Aug 8, 2014 17:52 |
|
ljw1004 posted:Wait, what? That's not what the link says. It says: I don't think that's completely true. See this other Jon Skeet link about what happens without an explicit static constructor: http://codeblog.jonskeet.uk/2010/01/26/type-initialization-changes-in-net-4-0/ EDIT: Though you are correct that it won't necessarily be called at startup.
|
# ¿ Aug 8, 2014 18:00 |
|
Ithaqua posted:Does anyone have any ideas about getting around SignalR's inability to have async event handlers? I'm working on something where I have my application's logic totally platform-agnostic and want to fire events when the internal state changes and needs to be pushed to clients, but SignalR can't handle async void methods. We're doing something similar to this, but are using a homegrown messaging abstraction (that we're later going to hook up to Azure pub/sub or a messaging queue). Instead of using C# events, we register for a message type with a callback.
|
# ¿ Aug 14, 2014 20:59 |
|
I've never really liked switching on/off timers if it wasn't necessary. It always seemed kind of janky to me. I would probably just leave the timer running and then perform some check in the callback to see if it should early return. That way you have control over any locking you might need to perform for the check, etc. instead of just depending on the timer's Enabled property.
|
# ¿ Aug 16, 2014 02:21 |
|
NoDamage posted:Have not found a good solution for (2) yet, but I am starting to get the impression that people just Refresh() their data when changes occur out-of-band from the UI. Is there no better way? I'd say do this until you have a good reason not to (e.g. performance) since it makes the code a lot simpler. In most applications, you're just not going to run into that performance wall. Computers are faster than you think.
|
# ¿ Aug 16, 2014 22:27 |
|
Mr. Crow posted:With me anyway, it seems like the more hair raising and obnxious the issue, the more likely it is to be something trivial I'm overlooking. I once spent an hour combing through VS bug reports trying to figure out why my loving tests in one single file wouldn't run. My co-worker pointed out that my class wasn't public.
|
# ¿ Aug 18, 2014 15:09 |
|
IdentityMatrix posted:Not sure where that event handler is hooked up, but are you unhooking the event handler when shutting everything down? And have you tried pw.Show() instead of pw.ShowDialog() or would that impact the execution path? ShowDialog() vs Show() shouldn't make a difference in WPF. However, I bet there is still a dangling event handler somewhere around there.
|
# ¿ Aug 19, 2014 14:37 |
|
Ithaqua posted:It feels wrong, but I can't express what's so wrong about it. I hate the ever-living poo poo out of it, but I also have an imbalanced dislike of dynamic in general. As Destroyenator said, you have a public interface with a lack of compile time type/typo checking. You could use Tuple to gain those benefits, but the code is still ugly with .Item1, .Item2. I feel like there's a happy medium that should exist in the language that's best described as "public anonymous types" or maybe "structural types" in the loosest sense of the term. Though this is all rehashing old discussions. In your case, I would probably just define a public class nested in the class that is spawning the event. If it's only used in that specific case, then there's no need to clutter your namespace with the event definition. This goes directly against being a lazy jerk, though.
|
# ¿ Aug 21, 2014 04:30 |
|
Drastic Actions posted:EDIT: Oh yeah, this might be a good place for this. I looked through the recent commits and read some of the code, but I was trying to find some low hanging fruit to go after that would actually be warranted. Is there a list of goals or bugs specifically for the WinRT version? I briefly browsed their bug tracker but the different milestones didn't seem terribly relevant.
|
# ¿ Aug 28, 2014 01:58 |
|
Generally, you shouldn't JSON.stringify if you're using jQuery AJAX to GET. GET commands are (de)serialized as application/x-www-form-urlencoded because they have to be part of the query string (GET request bodies are ignored per the HTTP/1.1 spec). POST requests, on the other hand, can have anything in the body and will usually work on most servers as long as the Content-Type header is correct (e.g. application/json). Unfortunately, the default MVC model binder is rather terrible at deserializing complex objects from a query string. A lot of things have to fall into place to make it work, and it's generally not worth figuring it out over just POSTing.
|
# ¿ Sep 4, 2014 21:40 |
|
Mr. Crow posted:Missed opportunity to I am ashamed.
|
# ¿ Sep 5, 2014 01:53 |
|
GrumpyDoctor posted:edit: There had better be a better way to do this, as I am apparently unable to actually catch this exception. No matter where I put try/catch blocks, the exception slips through and brings my app down. Can you post some code? Are you explicitly catching SocketException, or catching any Exception? If you're just catching a SocketException and the TcpListener is on an async call, it's possible that an AggregateException is being thrown instead. EDIT: On second thought, this is probably unlikely. Back to line 1 - got any code? Bognar fucked around with this message at 14:38 on Sep 8, 2014 |
# ¿ Sep 8, 2014 14:36 |
|
GrumpyDoctor posted:I was able to fix it by changing the offending line to I'm very inexperienced with F#, but my read of that code is that you are calling Async.Start which is starting the server method on the threadpool. If you're not handling exceptions within that method, the exception can not be caught because it's running on a different thread as the first method in its call stack (and therefore not wrapped in a try/catch at any level). Is pageNo zero?
|
# ¿ Sep 8, 2014 18:34 |
|
darthbob88 posted:That might do it, but I don't understand async that well. I don't suppose I can get a demonstration, just a toy program? C# code:
|
# ¿ Sep 11, 2014 14:23 |
|
|
# ¿ May 2, 2024 02:55 |
|
mortarr posted:If you're after optional conditions in the where clause, there's always predicate builder. I highly recommend this library. I've used it in a few places when dynamically building expression trees and it's always worked as expected.
|
# ¿ Sep 16, 2014 14:12 |