Browsing 7239 questions and answers with Jon Skeet

scheduleAtFixedRate vs scheduleWithFixedDelay

What's the main difference between scheduleAtFixedRate and scheduleWithFixedDelay methods of ScheduledExecutorService? scheduler.scheduleAtFixedRate(new Runnable() { ...
Jon Skeet
people
quotationmark

Try adding a Thread.sleep(1000); call within your run() method... Basically it's the difference between scheduling something based on when the previous execution ends and when it (logically) starts. For example, suppose I schedule an... more 7/9/2014 9:26:26 AM

people

ulong[] to uint[] is this good practice?

I stumpled upon this problem and saw this solution: ulong[] ulongArray = { 1, 2, 3, 4 }; uint[] uintArray = null; uintArray = (uint[]) (object) ulongArray; ulongArray =...
Jon Skeet
people
quotationmark

While that will compile, it will throw an exception at execution time. The two types just aren't compatible. A similar situation would be: uint[] uintArray = { 1, 2, 3, 4 }; int[] intArray = (int[]) (object) uintArray; That will work -... more 7/9/2014 9:14:58 AM

people

how to wait until a web request with HttpWebRequest is finished?

I am doing a web request to login in a my web services and I have a problem. I need to wait until the login is finished before end the method that launchs the login because I need...
Jon Skeet
people
quotationmark

Just use the newer style of asynchrony: using (var response = (HttpWebResponse) await request.GetResponseAsync()) { ... } You shouldn't need to call BeginXXX much now - certainly the Microsoft APIs have pretty universally added... more 7/9/2014 9:12:22 AM

people

Type casting object[] to generic type K which is also an array

I try to write a generic type casting method which will work for both complex objects and arrays of objects. Below is my code: public void Test() { MyClass2[] t2 =...
Jon Skeet
people
quotationmark

Fundamentally I think you want to avoid using List<object> at all. You should just create the array of the right size: IList dest = Array.CreateInstance(ek, sourceList.Count); for (int i = 0; i < sourceList.Count; i++) { ... more 7/9/2014 8:58:09 AM

people

Noda Time zone Format

I am using the Noda Time library. My code is var timeZone = NodaTime.DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Amsterdam"); above line of code gives me value like this...
Jon Skeet
people
quotationmark

Well, the result of the line of code you've given is a DateTimeZone. That has a MinOffset and a MaxOffset, but that's a different matter. You can find out the current standard and wall offset using: IClock clock = // some clock, e.g.... more 7/9/2014 7:31:53 AM

people

how to read a unicode encoded file in java

I am trying to read a file that has been encoded in Unicode(I used Editplus to find out its encoding.) I am using the following code:- InputStream inStream = new...
Jon Skeet
people
quotationmark

I'm not sure what endianness "Unicode" gives, but you should try "UTF-16BE" and "UTF-LE" - obviously BE is Big Endian, and LE is Little Endian. (Just which byte comes first in each 16-bit code unit.) (I've just read that "UTF-16" defaults... more 7/8/2014 5:38:31 PM

people

how to use nodatime for persian in c#?

nodatime 1.3 released , but i want to use nodatime in c# for Persian date time . how can i show Persian date time with Noda Time? var london =...
Jon Skeet
people
quotationmark

You need to explicitly use the Persian calendar. For example: var calendar = CalendarSystem.GetPersianCalendar(); var zone = DateTimeZoneProviders.Tzdb["Europe/London"]; var now = SystemClock.Instance.Now.InZone(zone, calendar); // Now... more 7/8/2014 5:25:42 PM

people

How to check extension of file using Platform::String?

I'm trying to check whether StorageFile is a zip file. I can convert the StorageFile to it's full name including it's extension. However there are very little helpful methods...
Jon Skeet
people
quotationmark

Given the name, I'd expect Path.GetExtension to work for you, if you're using the .NET "view" of WinRT. (I don't know if there's a direct equivalent in WinRT itself. Looking now.) more 7/8/2014 5:10:29 PM

people

StackOverflowError when creating an object of another class

I am working on a game for the past month or so and no matter what I do, I almost always get a StackOverflowError. This is what it says in the trace : Exception in thread "main"...
Jon Skeet
people
quotationmark

Do I get the error because both classes are extending each other and both are superclasses ? No, that would be impossible at the language level. It wouldn't compile. However, if creating a Player requires creating a Hole, which... more 7/8/2014 4:44:40 PM

people

CreateInstance from Type name and Assembly name

I'm trying to create a class using Activator.CreateInstance(assemblyName, typeName) but I am getting the error An unhandled exception of type 'System.TypeLoadException'...
Jon Skeet
people
quotationmark

It sounds like you do have the assembly - just not the namespace-qualified type name. You can fetch all the types in the assembly, and get the type from that: var type = typeof(IAssessmentObject).Assembly ... more 7/8/2014 3:19:28 PM

people