|
Okita posted:Kind of unrelated, but I thought I'd share some cool stuff I found out about System.Linq.Expressions. If anyone has used a javascript graphics/game library(such as Phaser or EaselJS) in the past, they know how tweening is done there. Your solution is nice and elegant. I just want to flag that if you're doing tweening in XAML for WPF or Metro, then it works best if you use the inbuilt tweening stuff which runs off the UI thread and so is smoother.
|
# ? Dec 27, 2014 17:47 |
|
|
# ? May 22, 2024 14:17 |
|
chippy posted:Can I use a List of Strings as a the key for a dictionary? Honestly, I'd just sort the list, then concatenate it into a single string using some kind of delimiter that's not in the strings (e.g. vbCrLf), and use the resulting SINGLE string as a key.
|
# ? Dec 27, 2014 17:50 |
|
Rocko Bonaparte posted:Ahh that is right. I keep relearning not to use ArrayLists. I should figure out an IDE extension to yell at me when I type it. The way to do this is with a "Roslyn Analyzer" - http://roslyn.codeplex.com - which will be part of VS2015, currently in preview. The way it will work is... (1) You can do File>New>...>DiagnosticAndCodefix to create one, but all it is is basically just a DLL with a well-defined entry point. (2) Anyone who wants can add a reference to your analyzer under the new References>Analyzers node (or as a NuGet package). (3) The analyzers are run live as people type in the IDE, so they'll get warning squiggles immediately they use an ArrayList. They also get run by the compiler when you do a project-build. And they get run by build servers in the same way. (4) The compiler, while it's compiling, calls into your analyzer. Your analyzer gets the opportunity to look at the types of symbols that are being used (and can look at pretty much anything else it wants). If it detects that one is an ArrayList, then you'll have it report a warning. You can also easily write a quick fix which suggests to the user to use "List<object>" instead. The VB/C# team is currently moving all the old FxCop rules into this new "Analyzer" system. And people are creating lots of extra analyzers on github+nuget for general consumption: https://github.com/code-cracker
|
# ? Dec 27, 2014 17:59 |
|
Rocko Bonaparte posted:I have a collections data structures question about ArrayList. I am in a situation where I wanted to use one, but the data I'm inserting into it is be placed in reverse-order. So I'm adding to the beginning every time. Is there any reason this is suboptimal for that container? I was wondering if, say, its default array started with i=0 and I immediately wreck it. I wonder then if it compensates in the second internal array it makes, or what. Use a stack instead, I have found that whenever a stack or a queue is suitable for a problem it's almost always the right choice. That you get to feel smug about using proper data structures is just a bonus
|
# ? Dec 28, 2014 11:23 |
|
xgalaxy posted:I don't really agree with this in practice. On mobile ArrayList performs better than generic List. In fact on mobile avoiding generics as much as possible helps performance a ton. This is using the Xamarin mono runtime not official runtime. So this may not be relevant for Windows Phone stuff. Wow, what design decisions were made there that caused generics to be slower? I thought C# generics were just syntactic sugar for the compiler to create additional classes at compile time. There shouldn't be any reason that those are significantly slower (I say from my armchair).
|
# ? Dec 28, 2014 23:49 |
|
Bognar posted:Wow, what design decisions were made there that caused generics to be slower? I thought C# generics were just syntactic sugar for the compiler to create additional classes at compile time. There shouldn't be any reason that those are significantly slower (I say from my armchair). Nope, generics are actually supported in the CLR. You might be thinking of Java generics. [edit]Unless you're talking about the JITer when you say "compiler", in which case yeah. New Yorp New Yorp fucked around with this message at 00:01 on Dec 29, 2014 |
# ? Dec 28, 2014 23:59 |
|
Bognar posted:Wow, what design decisions were made there that caused generics to be slower? I thought C# generics were just syntactic sugar for the compiler to create additional classes at compile time. There shouldn't be any reason that those are significantly slower (I say from my armchair). I was about to ask the same thing. Are there any articles that back this up? This seems really bizarre to me. Hopefully it changes when MS sacks up and buys Xamarin.
|
# ? Dec 29, 2014 07:19 |
|
Say I have a List<object> called my_list. I pass that list to method that uses a backgroundworker to write everything in the list to a file, but during the write, the main thread does a my_List = new List<object>(); (not my_list.clear())... Does the background worker keep the original list until it's done with it, or have I destroyed my write? If I have destroyed it, is the best thing to do just to copy the objects to a new list first?
|
# ? Dec 29, 2014 22:29 |
|
If you call a method and provide your list as an argument, you provide a reference to the list object. If you now change the variable that used to reference this same list, all you do is change the variable - the original list remains as-is and the reference given to the method does not retroactively change. Variables are just convenient names used to reference objects but changing what objects variables reference does not affect the objects they reference. Understanding the difference between variables and objects (instances) is the key here. Furthermore, know that you cannot destroy objects in C# - they will be destroyed automatically and only when they are no longer referenced by any variables. Presumably your background worker still references your original list via a variable (otherwise it could not use it) so it will remain in existence until the background worker finishes its work. A different scenario worth noting is that in some situations, variables themselves can be captured - there can exist one shared variable that is used in multiple places. In this case, the problem you fear might occur. Mainly, you will encounter this when using lambdas. code:
code:
EssOEss fucked around with this message at 23:23 on Dec 29, 2014 |
# ? Dec 29, 2014 23:19 |
|
bobua posted:Say I have a List<object> called my_list. I pass that list to method that uses a backgroundworker to write everything in the list to a file, but during the write, the main thread does a my_List = new List<object>(); (not my_list.clear())... code:
If it's a field in a class and your background worker function references it, then assigning new value to it while it's used by another thread will cause problems. code:
If your backgroundworker function is anonymous function within the body of a function which contains my_List, then you also shouldn't change it. code:
Forgall fucked around with this message at 23:32 on Dec 29, 2014 |
# ? Dec 29, 2014 23:29 |
|
Also, writing to a file isn't CPU-bound, so don't use a Background Worker -- use natively async methods (in the Stream-derived classes). The general guideline is: Async/await for I/O-bound operations (file I/O, hitting web services, retrieving data from databases, etc) Threads for CPU-bound operations
|
# ? Dec 29, 2014 23:30 |
|
Good explanations. Thanks!
|
# ? Dec 29, 2014 23:53 |
|
Ithaqua posted:Also, writing to a file isn't CPU-bound, so don't use a Background Worker -- use natively async methods (in the Stream-derived classes). I'm trying to do this, but I'm not using a regular .net method to write the files, I'm using this - http://www.emgu.com/wiki/files/2.3.0/document/html/a6b9b293-3647-ecfe-6754-920a5a46f394.htm which I don't think is async. Should I write my function to use async and call .save from in there, or am I going about this wrong?
|
# ? Dec 30, 2014 00:29 |
|
If you are using a library that is not async-aware then no, it is not possible to make it meaningful in an async scenario. I think the approach you use is OK in this case, assuming that you actually do need it to happen in the background. Memory fails me, though, on what exactly a BackgroundWorker does - I assume it is just an equivalent of creating a new thread? I tend to just create a new thread directly in such a case, if I have a potentially long-running non-async thing to execute in the background.
|
# ? Dec 30, 2014 09:40 |
|
So that's interesting, when you have [DataContract] attribute on base class, but not on child class, DataContractSerializer serializes public properties of child class just fine, but not private ones. To make it work with private fields/properties you need to put [DataContract] on child class as well. That's a bit strange. Edit: Also you need [DataContract] on child class if it doesn't have parameterless constructor, even when child class doesn't have any DataMemebers of its own. Forgall fucked around with this message at 12:03 on Dec 30, 2014 |
# ? Dec 30, 2014 11:30 |
|
Forgall posted:So that's interesting, when you have [DataContract] attribute on base class, but not on child class, DataContractSerializer serializes public properties of child class just fine, but not private ones. To make it work with private fields/properties you need to put [DataContract] on child class as well. That's a bit strange. I think you probably need to add the data contract on the child class if you want the system to know that the class should be serialized even though it doesn't have any data members because it requires the parameterless constructor to create the instance when deserializing, so the only way to tell the system that "yes, I want the base class A of this child class B serialized" is to actually put the contract on child class B, because otherwise with no data members and no parameterless constructor in class B, it probably doesn't bother trying to check for the base class A. At least, I think that's how that would work. Also I'm sorry that I missed out on the windows service scheduled operation talk. I spent way too much poo poo on that sort of thing in the past and I have lots of opinions on how it should be done.
|
# ? Dec 30, 2014 12:55 |
|
genki posted:Uh, what? I don't understand, this seems like a fairly basic OO concept. If you put a data contract on a base class, then the child class has private properties, how would any part of the system know that the child class private properties should be serialized? The base class has no visibility into those. code:
code:
Ok, I got it now, DataContractSerializer just acts like old XmlSerializer on types not marked with [DataContract] (and this attribute is not inheritable), as a silent fallback I guess. That confused me a bit.
|
# ? Dec 30, 2014 14:27 |
|
EssOEss posted:If you are using a library that is not async-aware then no, it is not possible to make it meaningful in an async scenario. I think the approach you use is OK in this case, assuming that you actually do need it to happen in the background. At some point you (meaning any developer) will need to be able to achieve concurrency with their lowest-level functions though, right? I mean, the be-all and end-all of async isn't "use the magic methods in MS-provided libraries or gently caress off." Right? I'm not being snide here, I'm still trying to get a handle on async and its ilk. Like, in bobua's case, his lowest-level method would look like this: C# code:
I'd really appreciate some words on this from someone who has some real experience with async, because this is one of those sticking points that's preventing everything from really clicking in my head.
|
# ? Dec 30, 2014 14:59 |
|
Che Delilas posted:At some point you (meaning any developer) will need to be able to achieve concurrency with their lowest-level functions though, right? I mean, the be-all and end-all of async isn't "use the magic methods in MS-provided libraries or gently caress off." Right? I'm not being snide here, I'm still trying to get a handle on async and its ilk. Okay, here's the definitive answer from the .NET team: Yes you're right. That "Task.Run" is exactly how you'd get it to work in this case, and the rest of your code can happily be async. However if you're writing code for server-side applications, or code that goes in a library which might be used server-side, then Task.Run isn't a good approach. This is subtle... * In server-side code, let's say your ASP.Net server can happily handle 1000 concurrent requests by using one thread per request. But if this request actually ends up using Task.Run and so consumes two requests, then it'll end up only being able to handle 500 concurrent requests. Thus the Task.Run hasn't actually achieved anything useful. * The right way to think about this is that the threadpool is an "application-wide global resource". If you write a library which secretly uses up that global resource, without the app-author even being aware of it, then you've done a disservice. It would have been better for your library to expose it as a synchronous method so that the top-level app author can make their own decisions about when to use the threadpool. So yes, if you want to make something purely async, that really is async all the way down, then it has to be built out of async primitives all the way down. The authors of emgu themselves would have to expose save+load methods that call into the OS's asynchronous APIs. Anything else is just a bandaid.
|
# ? Dec 30, 2014 17:13 |
|
ljw1004 posted:Okay, here's the definitive answer from the .NET team: That's really, hugely, fantastically helpful to me, thank you.
|
# ? Dec 30, 2014 18:17 |
|
ljw1004 posted:* In server-side code, let's say your ASP.Net server can happily handle 1000 concurrent requests by using one thread per request. But if this request actually ends up using Task.Run and so consumes two requests, then it'll end up only being able to handle 500 concurrent requests. Thus the Task.Run hasn't actually achieved anything useful. You would still be able to handle 1000 concurrent requests in this situation since the method awaiting Task.Run is suspended, so another thread can handle another request. You still haven't gained anything by using Task.Run, but you haven't cut your performance in half either (assuming you're using a synchronous method). I know ljw1004 understands this next part, but this is for anyone else having trouble grasping async/await benefits. If you have a method that's asynchronous, such as I/O for reading from a disk or network traffic, while your code is waiting on the completion of that method the calling thread is freed up to do other things. So, in the above ASP.NET example, if half of the time spent in a request is reading a file from disk and the other half is processing it, an async I/O method would let your serve twice as many requests per second as a synchronous I/O method since all of the time that you would have spent waiting on I/O can now be spent processing data on other requests. This is a pretty good article to read. Check out the section titled "What About the Thread Doing the Asynchronous Work?"
|
# ? Dec 30, 2014 19:34 |
|
Bognar posted:You would still be able to handle 1000 concurrent requests in this situation since the method awaiting Task.Run is suspended, so another thread can handle another request. You still haven't gained anything by using Task.Run, but you haven't cut your performance in half either (assuming you're using a synchronous method). Does the main thread of an application come from the thread pool too?
|
# ? Dec 30, 2014 20:10 |
|
The "main thread" is kind of irrelevant in a server scenario, but no it doesn't "come from" the thread pool. In a client application, your main thread is the UI thread and it is not managed by the thread pool. I should note, though, that you don't need a thread pool for asynchronous programming. The C# implementation of asynchrony is closely tied to a thread pool, but it's possible to do things asynchronously with a single thread (like JavaScript for example). EDIT: Unless by "main thread" in a server scenario, you mean the thread handling the initial request and not the thread used by Task.Run. In that case, yes, that thread is coming from a thread pool (though not necessarily the ThreadPool class) to avoid the expensive build-up and teardown of threads. Bognar fucked around with this message at 22:01 on Dec 30, 2014 |
# ? Dec 30, 2014 21:58 |
|
Pulling my hair out trying to bind to a treeview for the first time in wpf... I have a data structure that looks like this... List<Category> Categories; Category has a Name, and a List<Category> Categories & List<FeatureHolder> Features So... categories can contain a list of other categories and/or a list of features. A feature has no depth, but a category could be multiple sub categories deep. I can get categories to work in the treeview, and I can get features to show up, but only if a feature is 2 categories deep. A feature will never show up if it's under a top level category. code:
I needed to wrap the sub categories\featureholders in a component collection and make that the binding path, the do two seperate hierarchical datatemplates for them. bobua fucked around with this message at 23:40 on Dec 30, 2014 |
# ? Dec 30, 2014 22:39 |
|
Bognar posted:EDIT: Unless by "main thread" in a server scenario, you mean the thread handling the initial request and not the thread used by Task.Run. In that case, yes, that thread is coming from a thread pool (though not necessarily the ThreadPool class) to avoid the expensive build-up and teardown of threads. Yes, this is what I meant with my question. You said this: quote:You would still be able to handle 1000 concurrent requests in this situation since the method awaiting Task.Run is suspended I wasn't disbelieving you, by the way, I'm just trying to get a solid handle on this, and it's difficult when the very nature of the subject is so twisty.
|
# ? Dec 31, 2014 03:03 |
|
Che Delilas posted:I wasn't disbelieving you, by the way, I'm just trying to get a solid handle on this, and it's difficult when the very nature of the subject is so twisty. No worries, there's a lot going on and it's easy to get confused. Tasks in .NET are powerful because they are a combination of a lot of different concepts, but that also makes them hard to grasp. They are an abstraction over long running processes as well as asynchronous actions, and they can be used for parallelism as well as concurrency (they are not the same thing). It can be hard to separate all the ideas when they're all packaged up into one abstraction.
|
# ? Dec 31, 2014 04:40 |
|
Anyone that can summarize what the hell this doing since I don't know VB?Visual Basic .NET code:
Edit: Part 2: http://forums.somethingawful.com/showthread.php?threadid=2803713&pagenumber=691#post439697657 Knyteguy fucked around with this message at 21:05 on Jan 2, 2015 |
# ? Jan 2, 2015 21:01 |
|
Knyteguy posted:Anyone that can summarize what the hell this doing since I don't know VB? That Chr stuff is starting out as "http", maybe try decoding all the rest of it?
|
# ? Jan 2, 2015 21:05 |
|
Brain-dead obfuscation. The Chr() calls are outputting the value "http://1nil2thearsenal.com/ip.php?ip=" one character at a time. New Yorp New Yorp fucked around with this message at 21:17 on Jan 2, 2015 |
# ? Jan 2, 2015 21:06 |
|
Yeah they're putting a URL literal in code but apparently don't want people to be able to find that url by text search, maybe?
|
# ? Jan 2, 2015 21:09 |
|
Hm that looks like some sort of site compromise to me. Thanks for the help. Edit: yes it was compromised. Here's another version on another website: http://www.airdispatchinc.com/images/css.txt Knyteguy fucked around with this message at 22:44 on Jan 2, 2015 |
# ? Jan 2, 2015 21:11 |
|
I've got a fairly simple question that I'm having trouble Googling an answer for, for some reason. If I'm using Entity Framework to create a Code First database, and the entity A contains a List<B> of entity Bs, does the fact that I used a List mean that ordering will be preserved if I query out an A? Or do I need to manage ordering by hand?
|
# ? Jan 4, 2015 02:55 |
|
Scuzzywuffit posted:I've got a fairly simple question that I'm having trouble Googling an answer for, for some reason. I'm not particularly familiar with EF, but lists are not ordered data structures. I would not expect it to preserve ordering.
|
# ? Jan 4, 2015 03:39 |
|
Ithaqua posted:I'm not particularly familiar with EF, but lists are not ordered data structures. I would not expect it to preserve ordering. Looking at the table it generated, I'm guessing you're right. Thank you!
|
# ? Jan 4, 2015 04:29 |
|
Since when are lists unordered? Relations between entities are, sure, but the code equivalent of that would be a *set*.
|
# ? Jan 4, 2015 07:49 |
|
Yeah, lists are ordered, just not sorted.
|
# ? Jan 4, 2015 09:01 |
|
Have a very odd problem with system.speech from porting over some old code. I had a simple text to speech program running about a year and a half ago and my new company has a need for it as a POC. I grabbed the old code, did a quick quality of life update on it, and it ran fine locally. Once I moved it over to my rackspace VM just to work out any deployment quirks, I am getting a very odd error I am certainly not getting locally:code:
I have tracked down the problem to be when my tConvertTextToWav function. relevant code below: code:
code:
code:
Any help would be hot, thanks in advance.
|
# ? Jan 5, 2015 16:51 |
|
Catch and log the exception thrown in the ConvertTextToWav to see what it says? It seems likely that Speech Platform Runtime is not installed on VM, could be that.
|
# ? Jan 5, 2015 17:04 |
|
That was a good guess on the speech platform, but sadly that did not fix anything. No errors are being thrown. I used a simple text file writer (which I verified worked on the server) and no errors are being written to it. I just threw the conversion function into another thread and it seems to have solved the problem, despite it being listed as a synchronous operation. Odd indeed. Thanks for taking a look though.
|
# ? Jan 5, 2015 20:51 |
|
|
# ? May 22, 2024 14:17 |
|
Ithaqua posted:I'm not particularly familiar with EF, but lists are not ordered data structures. I would not expect it to preserve ordering. List<T> does preserve order though? IList<T> supports indexing by number so it would be very odd not to have stable order. That said, you can just make EF entities use ICollection<T> which is probably a more accurate reflection of what's going on.
|
# ? Jan 6, 2015 04:07 |