Browsing 7239 questions and answers with Jon Skeet

FTP + GZipStream = 'File is broken' when unzipped

I am trying to use a GZipStream to compress a document prior to uploading to an FTP server. If I save the compressed file stream to disk just prior to uploading, the copy on the...
Jon Skeet
people
quotationmark

You're not closing (and therefore flushing) the zip stream until after you've uploaded it. I suspect that may well be the problem. Move this line to after the using statement that creates/uses/closes the GZipStream: FTPPut(ftpPutPath,... more 12/3/2014 10:51:27 PM

people

calling non abstract method in abstract class java

I have 3 classes. It seems basic question. But I can'nt find answer by googling. public abstract class Test { void t1() { System.out.println("super"); ...
Jon Skeet
people
quotationmark

Either you create a concrete class which doesn't override the method, or within a concrete class which does override the method, you can call super.t1(). For example: void t1() { super.t1(); // First call the superclass... more 12/3/2014 6:53:56 PM

people

Joda dateTime parser is adding milliseconds unnecessarily

I have the time in milliseconds which I need to convert to 2009-01-31T06:34:45Z using Joda library. I have written the below program but the date parser is adding milliseconds by...
Jon Skeet
people
quotationmark

.000+05:30 is getting added to the dateTime object No, it's included in the result of dateTime.toString(), that's all. A DateTime value doesn't have any concept of its own format - it's just a date/time/calendar/zone. If you want to... more 12/3/2014 6:30:36 PM

people

Improving conversion from List to List<Dictionary<string,string>> with Linq

I've a Key/Value table in my DB and I would return a List of Dictionary. The following code works fine for me but with a lot of data is not performing. note: r.name doesn't...
Jon Skeet
people
quotationmark

I suspect you want something like: List<Dictionary<string, string>> result; using (var db = new ExampleDB()) { result = db.FormField .Where(r => r.Form_id == 1) .GroupBy(r =>... more 12/3/2014 6:24:47 PM

people

Why should a void method be async to be able to await?

Assume I have a method that has void return type and that I need to await on an operation in this method. public void someOperation() { //dostuff var res = await...
Jon Skeet
people
quotationmark

I don't understand why. Because you need to tell the compiler that you're trying to write an async method. That's exactly what the document you're quoting means. The compiler could infer that from whether or not your method includes... more 12/3/2014 6:14:56 PM

people

Java util Timer Thread addition

Timer timer = new Timer(); // scheduling the task at interval timer.schedule(tasknew,100, 100); If this is added as part of a web-application at the startup, how is the task...
Jon Skeet
people
quotationmark

I just wanted to understand if we are creating any additional threads that is responsible for this task threads? Yes - from the documentation: Corresponding to each Timer object is a single background thread that is used to... more 12/3/2014 6:10:30 PM

people

How to avoid c# (winforms) creating pointers to forms?

In c# winforms, I am having a problem whereby this block of code will create two variables that point to the same form instead of two different instances of the form: Form formA...
Jon Skeet
people
quotationmark

If you want two forms, create two forms - two independent objects - by calling the constructor twice: Form formA = new LoginForm(); Form formB = new LoginForm(); Now they're independent objects. Note that there's nothing winforms... more 12/3/2014 5:47:17 PM

people

Forbid string & object concatenation

I am converting a bunch of strings in an api into classes. I am using extensively the compiler to help me with this, since I can replace some types in core apis, and follow the...
Jon Skeet
people
quotationmark

C# will happily add together a string and any user defined object. Is there a way to turn this into a warning or a compilation error? Yes - if you're using Visual Studio 2015 or higher :) You can use Roslyn to create your own code... more 12/3/2014 9:28:36 AM

people

Putting an object implied to be of a less derived type into a list of a more derived type

In this situation, I have a list of the more derived type and another of the less derived type. In order to avoid arbitrary clutter in the less derived list I wrote a foreach...
Jon Skeet
people
quotationmark

Is there a way to circumvent this issue? Yes - you cast it: foreach (A a in listA) { if (a.GetType().ToString() == "Test.B") { listA.Remove(a); listB.Add((B) a); } } That will compile, but it's still... more 12/3/2014 7:26:35 AM

people

Why adding element to JList makes it empty in this particular case?

As the title says, when i try to dynamically add an element to a JList, which is inside a JScrollPane, it becomes empty. I think it has something to do with multithreading. The...
Jon Skeet
people
quotationmark

It looks like you're blocking the UI thread in the loop - when you call accept(), that's going to wait for a new connection, which means the UI thread can't repaint the UI. You should do that in a separate thread. All UI interactions... more 12/3/2014 7:16:32 AM

people