I have a C# WinForms TabControl, with many controls on each tab page. When you start, not many user objects are loaded, but as you switch tabs, it seems to load the tab with controls, and USER objects grows and grows, eventually hitting the limit and crashing the program. USER Objects is at its max setting in windows. At the moment, it can't be radically redesigned to use less controls, so that is a requirement here to maintain the same amount of controls on each tab.
I'm trying to see if there is a way to after switching tabs, to actually force unload the previous tab, so that it releases its user objects, then if switching back to that tab, everything seems normal and loads that one again (and unloads the previous one). Or some way to mimic this which actually releases USER objects.
I made a test program showing the issue, which can be easily recreated. C# WinForms, added 72 text boxes on each tab. When you start up to Tab 1, Task Manager shows 94 User Objects. When I click Tab 2, it shows 168. They never go lower. This happens without adding anything extra, no events, etc. Adding 2 more tabs, it goes to 315. So this is definitely something going on that is never unloaded, but only after click to tab. I need to find a way to lower USER objects on non-used tabs.
Related
I'm new to programming and c# but I have a fully functioning app and wanted to add some more features... so I re-designed a section just re-designed no code added yet... I just added a new page and added 6 pivotitems and on each pivot 32 buttons... that's 192 buttons in total there just simple buttons nothing spectacular but why is it when I run the app on my device and navigate to the page that the flash of colour that appears when you 'tap the button' starts to slowy get less and less responsive to a point I can quickly tap 5 buttons then a few seconds later all the animations will eventually finish.
I can't believe that many buttons could slow down the app to near death or should it? if not how can I fix it as I genuinely need 192 buttons! separated into 32 on 6 tabs/pages
The more xaml controls which have to be added require work and memory allocations on the phone's part in a shared tight environment.
I had a situation where 100 map pin points each had a pop up dialog which gave extra information. Each one of those dialogs slowed down the app noticeably just like you see. I had to give up on preloading all 100 dialogs even hidden.
What I read is that there seems to be some duplication pivot control on a tab with certain amount of buttons. Maybe redesign it where you only show one tab, one pivot control and 32 buttons, then depending on the tab selection, re-use the current items, but simply change the text to give the appearance of a change.
Regardless you need to scale back in some fashion.
-- Also --
Is data being loaded asynchronously? Or can the data be loaded before the page even comes up, but asynchronously? I had a Silverlight app which loaded a lot of the data onto the VM before certain pages came up. I used that paradigm on my last WP8 project with good results.
Between those two you will be able to scale back the load of this page to something more manageable.
--- Update ----
Gave an example on the OPs other question here:
Can I swap a buttons content databind to a different databind in code?
For some reason Blend or VS 2012 express added
<Button.Background>
<ImageBrush Stretch="Fill"/>
</Button.Background>
in the button xaml once removing it the buttons are responsive again...
We have a custom session handler which stores a history of data for pages. We have a requirement where we need to store and identify unique sessions for every tab/window.
For simplicity let's just say I need a unique string for each tab i.e.
Window A - Tab 1 - ABCDEF
Window A - Tab 2 - CDEFGH
Window A - Tab 3 - EFGHIJ
Window B - Tab 1 - GHIJKL
Window B - Tab 2 - IJKLMN
I need these strings to be accessible immediately when any link is clicked or when any tab performs a postback.
We have an overly complication solution in place at the moment which generates these unique strings and saves them in the tab name and cookies and uses the window blur/focus events to determine when a page has been navigated away. It works well 'in the lab' but we do get problems with this 'in the wild'.
I guess the most 'reliable' way to do this would be to generate a unique string and place it on the querystring for every page and every URL on that page, that way it would be available immediately as you click on any link or post back, and you could move between tabs / windows freely. However that would take a significant rewrite and I wonder if I'm missing a more straightforward option.
Any suggestions welcome.
In the end we found an ideal solution to this. We don't have 'unique' sessions between tabs, we have 'unique' sessions for every page, ignoring tabs entirely.
We still use the blur/focus events to handle which tab the user is currently on, but that is only used to provide tab specific navigation history and is nothing separate to the session handling.
This seems to work well for our needs.
I am creating many usercontrols in an windows application in C# 3.5. I want to copy any usercontrol and paste it on another location of the MDIForm. Similarly in case of Cut option. I am using these three options in a contextmenustrip. And theses options are visible when I right click on the usercontrol. Can anyone tell me how It will be done at run time?
That requires giving the controls a new Parent. Explicitly supported by Winforms, they can even have no parent, quite a trick. You can do it directly by assigning the Parent property. Or by adding the control to another Controls collection, it will be automatically removed from the one it was in before.
Be careful, this flexibility comes with a price. It is also a source of a nasty leak that can crash your program after a while. That's caused by the no-parent trick, otherwise triggered by a Cut without a subsequent Paste. If you use Controls.Remove() or Controls.Clear() then the control is moved to the 'parking window', an invisible window created by the Winforms plumbing that acts as a temporary host. If you then don't either move the control to another parent or forget to call its Dispose() method then the control will live forever. Until your program runs out of resources or the user terminates the program.
The out of resources bomb ("cannot create window") typically happens after a few hours so is easily missed when debugging. You can see it in TaskMgr.exe, Processes tab. View + Select Columns and tick USER objects. Also tick GDI Objects and Handles to feel good about your program not leaking.
If you put the controls on a Panel then you can move them all together with just a single line of code by moving the panel.
You could remove the control from the ControlCollection in case of cut and cache it to add that control to some other form when pasted like you could do
panel1.Controls.Add(newPanelButton);// To add, you might have to change the control `Location` as per your need
panel1.Controls.Remove(newPanelButton);//To remove
In case of having cut/copy effect on the same form you could just change the Location of the control to the new location where you want to paste that control.
I'm trying to implement enhanced TabControl/TabPage classes, in order to achieve real TabVisible feature, since TabPage's Visible property doesn't work as expected.
I'm working with C# / WinForms / VS2005 / .Net FW 2.0; I've implemented the code this way:
http://csharp.pastebin.com/AUnzRQLw
And I've made a Form to test it, checking/unchecking CheckBoxes to show/hide some VisibleTabPage controls I've added (http..//csharp.pastebin.com/MkGJGx2G). But, after a
certain number of clicks on CheckBoxes, in a random sequence, the application starts to allocate more and more memory, and use some considerable amount of CPU to show/hide TabPage controls.
Can anyone point me out where is the bug?
It's a bit too much code to wrestle through. I however see you use methods like Remove() and Clear() without you ever calling the Dispose() method for a tab page. These pages get "parked" and will keep using system resources. Run Taskmgr.exe, Processes tab, View + Select Columns, tick User32 objects. You'll probably see this number going up without bound as your code is leaking the Handle for the tab page and all of its controls.
i have a winforms application. i have a user control with a lot of icons. the user can load this control on a form many times (in a tabbed layout). right now i am loading the icons each time the control is created (could be up to 50 times in teh app). is there any way to cache these icons in the application. if i did this, would that decrease the number of gdi handles that i am using as this is becoming an issue.
You can make a singleton class for each icon. The first reference it creates the handle. Subsequent calls uses the existing handle.
Without knowing more about your user control my next suggestion can be only be very general. But you could have a single bitmap layer on which you draw all your icons. The remaining elements of your user control would exists above and around this bitmap.
Unfortunately this idea may be problematic performance wise. Require you to refactor the code you all ready use for arranging icons. Finally it is non-institutive from how frameworks with a control-form structure ideally works.
We ran into a resource problem with entry forms for the parameteric shape we ship with our CAM software. Too many text entries caused various forms of strangeness and leaks. So we instead created labels with borders that looked like text entries and had ONE text entry (and a combo box entry too). When the user tabs, enters, or clicked the single text entry moved to the new entry and the label was setup for the previous entry.
This is totally a non-intuitive setup than how you would normally code this but it was the only way to deal with our resource problem.
In my experience it seems that GUI Frameworks have issues when you have to deal with dozens or hundreds of entries and that you have to approach the problem using a different design.
If the issue is the number of "icons" (not sure what you mean here) you can use Image-Lists. For example, a Listview control can reference icons in an image-list, instead of keeping a full copy for each item (not sure if this applies to your case though).