Some of the work on my current project requires accurately timing events, at a frequency of a few dozen per second (that means that each event has to follow the previous one within a few milliseconds). The resolution of those calls is so small, that even System.Threading.Timer can not handle it and lags behind.
After some searching, I found that Win32 Multimedia Timers are a good solution to this problem, as they are (probably) the timers with the highest resolution available on the platform. At the moment, there is no official wrapper for the API in the Framework and Leslie Sanford's article offers a nice implementation.
Just stumbled onto an exotic bug in the framework:
using System;
using System.Xml.Serialization;
using System.IO;
namespace Repro
{
class Program
{
static void Main(string[] args)
{
new XmlSerializer(typeof(StaticClass.NestedClass));
}
}
public static class StaticClass
{
[Serializable]
public class NestedClass
{
}
}
}
Even though there will never be a need to instantiate StaticClass, this will fail with an InvalidOperationException stating that "Repro.StaticClass cannot be serialized. Static types cannot be used as parameters or return types."
Weird.
[Update: There's another one! The reason I moved to XmlSerializer instead of SoapFormatter was because SoapFormatter doesn't support generics and now:
namespace Repro
{
class Program
{
static void Main(string[] args)
{
new XmlSerializer(typeof(C));
}
}
[Serializable]
public class A
{
}
[Serializable]
public class B<T> : A, IEnumerable<T>
{
// ...
}
public class C : B<int>
{
public void Add(int value)
{
// ...
}
}
}
The above code throws another InvalidOperationException, stating that 'To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy.'
Moving the Add method to B works and I could understand it if I actually wanted to serialize an object of type B, but come on!
I've tried re-implementing IEnumerable<T> in C, but that doesn't work either.
This is quickly becoming very frustrating.]