In the full .NET framework one would use ThreadPool.QueueUserWorkItem for that. Since that is not available I tried to do it by calling BeginInvoke on a delegate.
private delegate void AsyncDelegate();
private static AsyncDelegate asyncOnPlaybackFinished = new AsyncDelegate(OnPlaybackFinished);
public delegate void PlaybackFinishedHandler();
public static event PlaybackFinishedHandler PlaybackFinished;
private static void OnPlaybackFinished()
{
if (PlaybackFinished != null)
PlaybackFinished();
}
// This line throws a System.NotSupportedException
asyncOnPlaybackFinished.BeginInvoke(
delegate(IAsyncResult ar)
{
asyncOnPlaybackFinished.EndInvoke(ar);
}, null);
Anyone ever did something like this before on NETMF?
First, BegilnInvoke is used with GUI programming to run something in the thread created the GUI control.
Using firing an event means you notify all those that have registered for the event. It has no semantics for running in a seperate thread.
I assume you want to handle the event in a seperate thread.
You can build you own worker thread pool.
Create a queue for your work item, based upon the event.
Associated with the queue is an AutoReset object. Each time you place something in the queue you set the event.
You can then start a number of threads, which wait on the AutoReset object. When the AutoReset is set, one thread wakes up. This thread then extracts a work item from the queue, and processes it. When the thread is done, it then waits on the AutoReset event.
This is a basic description, you have to worry about locking on the queue, having a thread check the queue before doing a wait, and waking up and finding an empty queue.
Yes, it also uses a Dispatcher. But since there is no Application started, there is no dispatcher running on the NETMF system. So you need to create your own dispatcher so you can call the Run method in a while loop yourself. Else nothing gets dispatched…
hi there,
i do not have any hardware to test anything yet, still waiting for the spider to show up
i guess you are not using any UI Elements, so in that case a timer maybe more appropriate …
//when using UI Element you can hook into the UI Dispatcher.
dispatchTimer timer = new DispatcherTimer();
timer.Tick += new EventHandler(OnTimer);
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
public void OnTimer(object sender, EventArgs e)
{
//DO something... Refresh
}