Browsing 7239 questions and answers with Jon Skeet

BackgroundWorker having everything passed as delegate

I want to pass the whole code to the BackgroundWorker DoWork event. I see it like that var c = (MethodInvoker)delegate { object all =...
Jon Skeet
people
quotationmark

The problem is that you're calling Invoke from the call_DoWork method - and Control.Invoke invokes a delegate on the UI thread. You just want to invoke the delegate on the current thread: var work = (MethodInvoker)... more 4/5/2014 3:32:15 PM

people

How to write fixed length records in Protbuf net?

Here is the main part of my code to Serialize using Protobuf-net. I have a very large number of records that I loop through and write to file. I now want to make all records a...
Jon Skeet
people
quotationmark

After a quick look at the documentation, I think you want something like: [ProtoMember(1, DataFormat = DataFormat.FixedSize)] public DateTime DT; [ProtoMember(2,)] public double BidPrice; [ProtoMember(3)] public double... more 4/5/2014 10:53:33 AM

people

Best way to convert months into Milliseconds

I'm trying to convert a no of months into milliseconds For example: 6 months = X milliseconds
Jon Skeet
people
quotationmark

There's no fixed answer to that, because it depends on which months those are - and indeed which year it is. Also potentially which time zone you're in, if you want to take account of that. (I'm assuming you mean the Gregorian calendar, by... more 4/5/2014 8:30:41 AM

people

Given 2 objects: myPanel1 & myPanel2, If we add myPanel2 into myPanel1 many times, then why myPanel1.getWidgetCount() still = 1;

This code is in Gwt but if u just know Java then u still can be able to answer this question. Ok, i have 2 panels: myPanel1 & myPanel2, then I add myPanel2 into myPanel1 many...
Jon Skeet
people
quotationmark

I'm not a GWT developer, but I suspect this is calling Panel.add(Widget) which documents these steps (emphasis mine): There are several important things that must take place in the correct order to properly add or insert a Widget to a... more 4/5/2014 8:13:55 AM

people

Inserting field values into database

I can't seem to figure out why I'm getting this exception: SQLException: Parameter index out of range (1 > number of parameters, which is 0). My mysql connector version is...
Jon Skeet
people
quotationmark

You're not assigning a value to statement in that method, and you're using the overload of executeUpdate from Statement... rather than the parameterless one in PreparedStatement. I suspect you actually want to assign the statement using... more 4/4/2014 9:22:33 PM

people

Decrypt method returning null

I have this cryptography class. import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; public class Crypto { public Crypto(){ } public static...
Jon Skeet
people
quotationmark

Aside from everything else, the most fundamental problem you've got here is that you're converting binary data to a string just using the platform default encoding, as if it's actually just text. It's not - it's binary data. If you want... more 4/4/2014 8:17:20 PM

people

Make multiple async calls in a single call in C#

I want to make multiple asynchronous calls in a single call without using a loop. For example, I'd like to pass a list of URIs and and retrieve all of them asynchronously in one...
Jon Skeet
people
quotationmark

You can get a list of tasks very easily - for example: var tasks = uris.Select(async uri => { using (var client = new HttpClient()) { return await... more 4/4/2014 8:11:35 PM

people

Ternary operator for strings any nicer way?

I'm concerned about this construct: String out = "Text " + (obj==null ? "" : obj.getStr()+" ") + "text continues."; It works and all, but I think it's ugly. Maybe I'm just too...
Jon Skeet
people
quotationmark

Well you can separate out the logic from the format, to start with: String out = String.format("Text %stextcontinues", obj == null ? "" : obj.getStr() + " "); more 4/4/2014 4:26:51 PM

people

How get all results of Invoke method

I have very simple delegate: public delegate int Compute(int i, int j); and some functions: static int sum(int x, int y) { return x + y; } static int diff(int x, int...
Jon Skeet
people
quotationmark

You have to call MulticastDelegate.GetInvocationList, which will allow you to invoke one handler at a time: // TODO: Don't call your event e, and use Func<int, int, int> foreach (Compute compute in e.GetInvocationList()) { int... more 4/4/2014 3:38:58 PM

people

Override function from base class with a different enum

Okay, the title may sound a bit confusing, just read my explanation here to understand what I mean: I got a base class, lets call it BaseProvider. This class looks like...
Jon Skeet
people
quotationmark

No, absolutely not - and here's why... This code still has to work: BaseProvider provider = new TestProvider(); provider.NewItem(10); That's just the normal requirements of polymorphism. You can't change a signature when you're... more 4/4/2014 3:30:10 PM

people