ESP in the news

I’ve got another round of ESP news articles for ya.

Business Week

This one is a little old, from back in December, but if you haven’t seen it yet, take a look:

Business Week ESP Article

I particularly like the part about Northrup Grumman using ESP to create a prototype/Proof of Concept on page 2 of the article, since I got to spend a week up in Reston, VA working with this team to pull this off :->  I doubt every Service Provider who uses ESP is going to get a week of my time to help them out, but it was a lot of fun and they were a great group of developers to work with.

Training & Simulation Journal

TSJOnline.com has 2 articles on ESP:

First TSJOnline article – this one mentions Lockheed Martin and FlightSafety have signed up as partners.

Second TSJOnline article – this one is a more general article on Microsoft entering the Visual Sim market.

Games Developer Conference / Serious Games Summit

This next one is an article on Gamasutra about the GDC / SGS last week in San Francisco and the Microsoft ESP presence there – you even get to see a picture of our studio head, Shawn :->

GDC / SGS coverage

Microsoft MSDN

For those of you with a Microsoft MSDN account, you can now download the ISOs for Microsoft ESP for testing purposes from the MSDN Subscriber downloads section.

Microsoft ESP Home Page

Our home page has been updated with a short demo video, click and enjoy :->

 

That’s all for now, till next time

Tim "Beatle" Gregson

Advertisements

SimConnect and WPF

I’ve noticed some folks having problems using SimConnect with WPF based apps because there’s no easily accessed hWnd and no easily overridden DefWndProc.  Here’s a solution that works around those problems and is also usable in WinForms apps if you like.

In the existing managed samples provided in the SDK, the 2nd param of the new SimConnect(…) line is the hWnd and the 3rd param is the WM_Xxx based message to send to the main window.  For this solution, we will instead pass 0 for both of those params and pass an AutoReset EventWaitHandle object as the 4th param to that call.  Then we will create a background thread that waits for this event to fire and then calls the ReceiveMessage function to handle data received from SimConnect.

Here’s a couple of code snippets:

This first snippet shows the data used:

// data
Microsoft.ESP.SimConnect.SimConnect sc;
System.Threading.EventWaitHandle scReady = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);
System.Threading.Thread bgThread = null;
public delegate void MyDelegate();

And this next snippet shows the code that uses these data items:

// code
private void ConnectToSimConnect(void)
{
    sc = new Microsoft.ESP.SimConnect.SimConnect("VE_SC_WPF", (IntPtr)0, 0, scReady, 0);
 
    bgThread = new System.Threading.Thread(new System.Threading.ThreadStart(scMessageThread));
    bgThread.IsBackground = true;
    bgThread.Start();
}
 
private void scMessageThread()
{
    while (true)
    {
        scReady.WaitOne();
        this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new MyDelegate(scMessageProcess));
    }
}
 
private void scMessageProcess()
{
    sc.ReceiveMessage();
}

With the code above, all of the OnRecvXxx callbacks will still happen on the UI thread context, meaning the rest of your code can stay the same as it was when using the hWnd and WM_Xxx message with an overridden DefWndProc. 

If you would prefer that the message handling and the OnRecvXxx callbacks occur on the background thread context, you can do that with this code snippet instead:

// code
private void ConnectToSimConnect(void)
{
    sc = new Microsoft.ESP.SimConnect.SimConnect("VE_SC_WPF", (IntPtr)0, 0, scReady, 0);
 
    bgThread = new System.Threading.Thread(new System.Threading.ThreadStart(scMessageThread));
    bgThread.IsBackground = true;
    bgThread.Start();
}
 
private void scMessageThread()
{
    while (true)
    {
        scReady.WaitOne();
        sc.ReceiveMessage();
    }
}

Doing things this way will require you to handle any thread synchronization that might be required to access any UI elements within each OnRecvXxx callback, but if you aren’t accessing UI elements much in your callbacks, then the 2nd way might be more efficient overall, but will require more work on your part to insure things happen on the correct thread.

I’ve been playing around with WPF for the last couple of weeks and its a lot of fun and can do some really cool things (repeat after me, DataTemplates are your friend :-> ).  Hopefully the above code snippets will let folks out there write some cool WPF based SimConnect clients.

Tim "Beatle" Gregson