Browsing 7239 questions and answers with Jon Skeet

Wrapping a method with Task.Run( ... ) hangs when called in a Static constructor

I have a series of long-running functions. I want to wrap them in a Task so that I can run all of them concurrently, rather than waiting for each one to finish sequentially. The...
Jon Skeet
people
quotationmark

Your task, which will be running in another thread, needs to call _one. That method can't execute until your Program type has been initialized. The tasks's thread will see that the Program type is already being initialized in the main... more 12/8/2016 11:46:48 PM

people

Using local methods for querying data from DocumentDB

I have the following function in my base repository public IEnumerable<T> GetAll(ClaimsPrincipal user) { return...
Jon Skeet
people
quotationmark

However, am I correct in assuming that once I call .AsEnumerable() the query goes to the database Not quite. When this method returns, it won't have hit the database at all. AsEnumerable() doesn't force the query to execute - it's... more 12/8/2016 12:36:37 PM

people

What are the assembly types with name <>c?

I'm loading some assembly types of my Entities and some of then appears with this value "<c" in the name what are these types? And how do I ignore them? (whitout load it) If i...
Jon Skeet
people
quotationmark

They're C#-compiler-generated types, e.g. for anonymous types, iterator blocks, closures that capture local variables, and async functions. This is nothing to do with Entity Framework in itself. If you want to ignore all... more 12/8/2016 11:48:19 AM

people

dividing system.collections.bitarray into sub bitarrays of 32 bits each

I have searched in net but not getting exactly what I need. I have a bitarray of size 15,936. I need to divide this bit array into list of bitarrays , with each bit array having...
Jon Skeet
people
quotationmark

The first that you want 32-bit values makes this pretty easy, because you can copy it to an int[], then create one BitArray per int, passing the data by creating a single-element int array: int[] values = new int[bigBitArray.Length /... more 12/8/2016 9:23:38 AM

people

Get the actual value that failed the Parse

Disclaimer This question is about, If and How we can use the Parse method exceptions, to find which argument/variable had actually failed the conversion. It is NOT, to argue if...
Jon Skeet
people
quotationmark

Not reliably - there's nothing in the FormatException that does this for you. Parsing the message is very fragile - it can change in different versions of .NET, and it'll be localized. One option would be to write your own Parse method... more 12/7/2016 1:33:56 PM

people

Cannot infer generic type if it is returned

I have a very simple extension method (it's probably irrelevant though that it is extension and would be the same for ordinary ones): public static T Content<T>(this...
Jon Skeet
people
quotationmark

I don't see any problems with inferring that T is of type MyClass even without explicitly saying so Well, the problem is that the language isn't specified that way at all. Generic type inference is performed based on the arguments. A... more 12/6/2016 2:11:05 PM

people

Composed predicate in Java 8

In Guava, we can do stuff like Predicate<String> isEmpty = Predicates.compose(String::length, Integer.valueOf(0)::equals); // contrived, I know Can we do something...
Jon Skeet
people
quotationmark

You can easily write a compose method and use that in multiple places: import java.util.function.*; public class Test { public static void main(String[] args) { Integer zero = 0; Predicate<Integer> isZero =... more 12/6/2016 9:48:39 AM

people

Linq query to match multiple parameters

I am having a list of model which i populated with items. The below list is populated with items :- List<Entry> list = new List<Entry> { new Entry { EmployeeId =...
Jon Skeet
people
quotationmark

Logically, what you want is: var query = db.Table.Where(e => list.Any(le => e.EmployeeId == le.EmployeeId && e.EntryDate == le.EntryDate)); I don't know whether that will work... more 12/6/2016 9:32:21 AM

people

Can a read instruction after an unrelated lock statement be moved before the lock?

This question is a follow-up to comments in this thread. Let's assume we have the following code: // (1) lock (padlock) { // (2) } var value = nonVolatileField; //...
Jon Skeet
people
quotationmark

I believe this is partially guaranteed by the CLI spec, although it's not as clear as it might be. From I.12.6.5: Acquiring a lock (System.Threading.Monitor.Enter or entering a synchronized method) shall implicitly perform a volatile... more 12/6/2016 9:05:22 AM

people

Fast IEnumerable<enum1> to List<enum2> convertation

I have two same enums that have the same names of members, but they are in different namespaces so they are "different types", but in fact namespace1.enum1 {a,b,c,d,e,f} and...
Jon Skeet
people
quotationmark

Well something's going to loop somewhere, but it doesn't have to be in your code. Just a LINQ Select will be fine: var result = original.Select(x => (Enum2) x).ToList(); more 12/5/2016 12:53:05 PM

people