Browsing 7239 questions and answers with Jon Skeet

Fast Image Loading from Network Drive in C#

I have a C# application that needs to load about 50 TIFF images from a network drive. Each of these images has a size of about 10-15 MByte. I have to load these images, resize...
Jon Skeet
people
quotationmark

I suggest you copy them to a local drive first. I suspect that Bitmap.FromFile may seek around the file (possibly reading redundantly) in a way which isn't a good fit for network drives - whereas just copying the files locally and then... more 3/17/2015 9:50:36 AM

people

Task Parallel Library Task.Delay() usage

I am after some explanation of what's going on. //VERSION: Async private async void DoWorkAsync() { Stopwatch stpWatch = new Stopwatch(); _logger.WriteToLog("Doing some...
Jon Skeet
people
quotationmark

The Task.Delay statement seems to have no effect in the latter case, can i not use it without await keyword? Well you can't use it without doing something with the result. Task.Delay just returns a task that will complete later on.... more 3/17/2015 8:15:45 AM

people

Java Creating Object Arrays

I can't seem to work out these object arrays, I'm attempting to create a list of player names with values stored, each with an integer and some multiple strings for each. This is...
Jon Skeet
people
quotationmark

There are three problems with this code: Player[] player = new Player[userCount]; player[userCount].setName(name); Firstly, you're creating a new array each time - I suspect you want to populate userArray instead. Secondly, you're... more 3/17/2015 7:06:48 AM

people

Joining byte arrays using a separator in C#

I want something similar to String.Join(separator_string, list_of_strings) but for byte arrays. I need it because I am implementing a file format writer, and the specification...
Jon Skeet
people
quotationmark

I don't believe there's anything built in, but it's easy enough to write. Here's a generic version, but you could make it do just byte arrays easily enough. public static T[] Join<T>(T separator, IEnumerable<T[]> arrays) { ... more 3/16/2015 5:34:24 PM

people

How to get response body from httpclient c# when doing multipart

I am trying to post multipart data using System.Net.Http.HttpClient, the obtained response is 200 ok. Here is the Method I used: public async Task postMultipart() { ...
Jon Skeet
people
quotationmark

Hint: you're calling PostAsync, and awaiting the result... but then not doing anything with it. It's not clear why you're using ContinueWith either, when you're in an async world and can just handle it simply: var response = await... more 3/16/2015 2:14:45 PM

people

How to parse textfield to bigdecimal

Is it possible to parse BigDecimal from a textfield ? I have seen some code where they parse bigdecimal from strings. But is it also possible to use this on textfield. I have...
Jon Skeet
people
quotationmark

No, that's not how you should do it - you're currently parsing from a string to float, then converting that float to a BigDecimal. You clearly know how to get a string from a text field, because you're already doing it in the first line -... more 3/16/2015 1:53:43 PM

people

'system.argumentexception' When uploading multipart

I am trying to post multipart data using System.Net.Http.HttpClient but when I am instanciating my content I am getting this exception: A first chance exception of type...
Jon Skeet
people
quotationmark

# is invalid in a MIME boundary. From RFC 2046: The only mandatory global parameter for the "multipart" media type is the boundary parameter, which consists of 1 to 70 characters from a set of characters known to be very robust... more 3/16/2015 11:29:52 AM

people

Enumerable.Where() not possible on IEnumerable?

I have an XmlNodeList and want to call the .Where() to get a filtered Node-List. But this doesn't work. Now I'm wondering, why sometimes the .Where() works and sometimes not. How...
Jon Skeet
people
quotationmark

Most LINQ to Objects methods work on the generic IEnumerable<T> type, rather than IEnumerable. Unfortunately, XmlNodeList only implements IEnumerable. It sounds like you're just looking for Cast, which is what the query expression... more 3/16/2015 10:09:54 AM

people

Error when using generics with multiple generic constrains

I've inherited an application consisting of a basic framework of which I have no control over. Now some classes have changed there and I have to update our usage of it. The basic...
Jon Skeet
people
quotationmark

You're assuming that ClassCImpl is compatible with the T of your ClassB<T>. Suppose I have: public class OtherClassC : ClassC {} ... MainClass mc = new MainClass<ClassB<OtherClassC>,... more 3/16/2015 10:04:51 AM

people

Check system.nullreferenceexception

My code as follows: @{var UName = ((IEnumerable<Pollidut.ViewModels.ComboItem>)ViewBag.UnionList).FirstOrDefault(x => x.ID ==...
Jon Skeet
people
quotationmark

Well, you're calling FirstOrDefault - that returns null (or rather, the default value for the element type) if the sequence is empty. So you can detect that with a separate statement: @{var sequence =... more 3/15/2015 9:38:36 AM

people