开发者

Limitation in Number of Win Forms in C#

I am writing WinForms application, and so far it contains 37 forms. This is because of my project's needs.

My questions are:

  1. Is there a limitation to the number开发者_Python百科 of forms created in C#?
  2. Does it have an effect on application performance?

Thanks for your help.


Is there a limitation in forms creation in C# ?

AFAIK there is no such limitation imposed by the the .NET Framework. Obviously the more forms you create and keep in memory, the less memory you will have until you run out of it. And the less memory you have could lead to slower performance.

On the other hand if you keep in memory only the current form and leave the GC take care of the others by leaving their instances fall out of scope there won't be such problems.


There is no limit on number of forms until you run out of ram. It will affect both system and application performance though.


not that I know of, or other modules or classes within a project can create as many you'll need without any restrictions.

Regards.


I had an project with too many winforms in it(Approx 50). After 2 or 3 Debug Builds and Runs i used to get following error.

Error 1   Unexpected error writing metadata to file

'E:\Repository\Project\JewelSoft\PresentationTier\obj\Release\PresentationTier.exe' -- 'Not enough storage is available to complete this operation. ' PresentationTier

So take care and always implement GC where ever required.

Update 1: Although there are methods like GC.Collect(), you dont often require to implement it unless you have cases that your code ends abruptly or switches the threads. Things like Disposing the forms which are not required after closing and avoiding repetitive declarations of object will be helpful.

Update 2: To know more when are where to write GC.Collect please refer these links:

  1. GC.Collect()

  2. When to call GC.Collect

  3. When is it acceptable to call GC.Collect?

And about form dispose, on Form close method it will automatically get disposed, but then if you have an variable for that form in some other form then it is advisable to write form1 = null; in form1_disposed event

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜