0

私は持っていSystem.Drawing.Pen _penます。

いくつかの反復で設定すると、次の_pen.Width = 3ようになります。

System.ArgumentException 
  Message="Parameter is not valid."
  Source="System.Drawing"  - System.Drawing.dll
  StackTrace:
       at System.Drawing.Pen.set_Width(Single value)
       at MyProject.ctlPanneauGraphique.CustomLine.set_BorderWidth(Int32 value) in 
       ....
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at MySolution.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

何を、なぜ?

4

3 に答える 3

2

_pen 変数を破棄していますか?

そうでない場合は、ご想像のとおり、リソース リークの問題を示している可能性があります。

はいの場合、破棄されたインスタンスにアクセスしていることを示している可能性があります。GDI オブジェクトを破棄した後に使用すると、ArgumentException がスローされることがよくあります。

于 2010-02-18T09:30:24.260 に答える
0

_pen 変数をどのように初期化していますか? MSDN のドキュメントによると、Pens クラスを使用して変数を初期化すると、Width パラメータを設定できない不変の Pen が取得されます。そうしようとすると、ArgumentException がスローされますが、これはまさにあなたが見ているものです。

于 2010-02-17T18:58:56.463 に答える
0

私はそれがメモリリークの問題から来ていると思い始めました。どうやら、OS は 10.000 を超える GDI+ オブジェクトを作成できないようです...

いくつかの分析が実行された後、アプリケーションで大量のメモリ リークが検出されたため、そこからエラーが発生しました。

于 2010-02-18T09:09:49.977 に答える