Novick Software
SQL Server Consulting • Design • Programming • Tuning

  andy novick is a sql server mvp

 

 

Tips and Tricks for:  VB.Net, C#, .Net, WinForms, Windows XP

 

The Problem:   SEHException in System.Windows.Forms.UnsafeNamtiveMethods.DispatchMessageW

This usually shows up several levels in the stack below the Application.Run(myForm) call.


Solution: Add a Application.DoEvents right after EnableVisualStyles or remove any use of Application.EnableVisualStyles.

Application.EnableVisualStyles is used to turn on Windows XP theme support in some of the WinForms controls.  However, once I turned it on, this exception started being raised.  Removing the call to Application.EnableVisualStyles removed the problem.  I'll can live without theme support.  However, it appears that if there is a Application.DoEvents right after the Application.EnableVisualStyles, the exception doesn't get raised.  Go figure?  So your code should read.

    Application.EnableVisualStyles
    Application.DoEvents

    ' Now go and set the FlatStyle to system....

I found confirmation of this in some newsgroup postings and at a Microsoft Developer Days presenation.


RSS as HTML

Personal Blog

 
New Tips:

Use dsinit to set the SQL Server instance for Windows Azure dev storage

Upcoming
Presentations:

SQL PASS
Nov 7, '12
Biggest
Loser: DB
Edition


Full Schedule