.NET 2.0には古いバグがあります。ただし、このバグはターミナルサーバーまたはリモートデスクトップ/アシスタンスセッションでのみ発生します。
詳細情報や回避策: http://support.microsoft.com/kb/953389
更新月2017年のMicrosoft KB953389の記事を削除しました。それはまだいくつかの検索エンジンによってキャッシュされています。ここで
とは何かと言う:
アクション
あなたは、Microsoft .NET Framework 2.0のWindowsターミナルサーバーセッションでFormsアプリケーションを実行しています。その後、端末サーバのセッションウィンドウを最小化したり、セッションを切断したり、セッションをロックしたりします。 結果は
ターミナルサーバーセッションでの作業を再開すると、Windowsフォームアプリケーションを
は、次の例外が表示され、スタックの呼び出し:これは、Microsoftのバグによるものである
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
at System.Drawing.Graphics.Clear(Color color)
at System.Windows.Forms.ToolStripProfessionalRenderer.OnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)
at System.Windows.Forms.ToolStripProfessionalRenderer.OnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)
at System.Windows.Forms.ToolStripRenderer.DrawToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)
at System.Windows.Forms.ToolStripContentPanel.OnPaintBackground(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmEraseBkgnd(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
原因
.NET Framework 2.0。 Windowsフォームの実行時に、System.Drawing.Graphics.Clearを安全なデスクトップで実行されているかどうかを確認せずに呼び出すよう試みています。次のMSDNリンクに記載されているように、ターミナルサーバーセッションでセキュリティ保護されたデスクトップでClearメソッドが呼び出された場合、ExternalExceptionが発生し、Graphicsオブジェクトが矛盾した状態になることがあります。
Graphics.Clear方法
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.clear.aspx
解像度
あなたはApplication.ThreadExceptionイベントにイベントハンドラを配線することにより、この現象を回避することができます。このイベントにより、アプリケーションコードは、Windowsフォームスレッドで発生する未処理の例外を処理できます。これにより、表示される標準Windowsフォーム例外ダイアログの代わりにコードを呼び出すことができます。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Application.ThreadException, AddressOf Application_ThreadException
End Sub
Sub Application_ThreadException(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
If TypeOf (e.Exception) Is System.Runtime.InteropServices.ExternalException Then
Return
End If
MessageBox.Show(e.Exception.Message, Me.Text)
End Sub
GDI +の例外はかなり厄介ですが、これはほとんど常に許可の問題です。ファイルが書き込まれている場所とユーザーがサーバー共有に対して適切な権限を持っていることを100%確認してください。また、書き込みしようとしているファイルがネットワーク上の別のマシンによってロックされていない可能性があります。 –