N S

Novick Software Management • Design • Programming • Training • Consulting

   

 

 

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:

Loading SQL Profiler trace (.trc) files with fn_trace_gettrace

Upcoming
Presentations:

Big Data:
Working with Terabytes
in SQL Server

July 9 '08


Full Schedule