views:

270

answers:

2

I'm creating a new DispatcherTimer() in Silverlight 2.0, and the constructor call throws an exception:

DispatcherTimer timer = new DispatcherTimer();

This line throws before I can set Interval, Tick, or Start the timer.

System.Exception was unhandled by user code
  Message="Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
  StackTrace:
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.CreateObjectByTypeIndex(UInt32 typeIndex)

(The next line of the stack trace is the constructor call, and it goes on in my code)

I'm not yet starting the timer or setting the interval, only calling the parameterless constructor. Any ideas what's wrong here?

A: 

Can you post your code? Here is what I use ...

System.Windows.Threading.DispatcherTimer pageTimer = new System.Windows.Threading.DispatcherTimer();
pageTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); // milliseconds
pageTimer.Tick += new EventHandler(Each_Tick);
pageTimer.Start();

Make sure you have the event handler defined too.

typemismatch
+1  A: 

You are likely creating the DispatcherTimer in a non-UI thread, or at an invalid time (before calling InitializeComponent, or the Application starts up, etc.).

Is this still an issue for you?

Jeff Wilcox