|
Dave Kreskowiak wrote:
dhn is partially correct. The GC is pretty lazy, but not as bad as he makes it sound.
Everything I say sounds bad these days cuz I feel like that. That is, bad. Yeah I was quite incorrect. Thanks. OTOH I belive he follows that link I gave him... so he can correct my mystifications
David
|
|
|
|
|
Make sure you dispose of absolultey every thing the moment you have writen it to the screen.
If you write a bitmap to screen... dispose of it.
if you draw a line dispose of the pen and/or brush and the graphics object as soon as you have drawn it.
Dont think because its on screen you should not dispose of it until you no longer need it on screen... draw it then dispose of every graphics element(Bitmaps, clones, pens, brushes, graphics objects) it used.
I wrote a simple app that used cloned portions of a bitmap as brushes and painted them to the screen... i didnt get many brushstokes done before i hit an "Out of memmory" error when depending soley on the GC.
|
|
|
|
|
Well, because you relied on the GC to call the .Dispose() methods for you, you we're using unmanaged system resources faster than the GC could free them. The GC doesn't track unmanaged resources used (short of memory anyway) so it can't tell that the system is running low on stuff like Handles. It's very unlikely you actually ran out of memory, rather it is more likely that you blew through tens of thousands of handles.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
ltinka wrote:
When I force thumbnail image to dispose (calling Image.Dispose()), nothing change.
You need to make sure you do this, or your memory usage will grow
ltinka wrote:
I have a suspicion that memory usage of my app growing gradually till some moment when system tells user there is not enough virtual memory.
If the GC has not kicked in before then, it will do so in time to stop this.
ltinka wrote:
I'm afraid that times of malloc() and free() are gone, but...
No, if you have large objects like media files or images in your app, you need to handle your own memory. malloc and free are long gone though, unless you came to C# from C and not C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks a lot. My app is in development for nearly 18 months and there are huge amount of code to repair by Dispose() calls ( ).
|
|
|
|
|
Im trying to develop an application that will login to an Exchange Server (using 2000 at my job) and poll to see if any new messages are in a particular inbox i.e. my own.
Any suggestions on how to do this in C#? I'm relatively familiar with C# and if any clarifications are needed on what I'm trying to do, please let me know.
Josh Kierpiec
|
|
|
|
|
Hello,
I'm writing my own print preview window using a PrintPreviewControl . I can't find where to get the total number of pages (so I can provide page navigation.) PrintPreviewDialog does it, but I can't find a property.
I've thought on incrementing the StartPage property until it throws an exception (will it? the docs say nothing) but there should be a better way.
Any ideas? Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I've solved my problem, so I'll share with you
In the contructor I set the StartPage property to a huge number (say, 1 billion). Then I install the StartPageChanged event handler. After the print preview is generated, I get that event, with StartPage set to the last. I save the page number, and then restore it to the first page.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Does anyone know what needs to be done to programmatically check or uncheck a checkbox in Excel using C# (or even VB.Net)? I already have the code to open an excel document, change cells, update links, save, and close, but the checkboxes are killin me.
I have tried using the Worksheet.CheckBoxes(object Index) method to try and retrieve a CheckBox object, but it doesn't work. It returns an obscure COM error. I tried it by using both the checkbox name and a number for the Index parameter. When attempting to generate a macro in excel to change the value of the checkbox, no code is generated when performing actions to the object. I don't want to have the checkbox link to a cell, and change the cell to control the checkbox -- that is lame. But if no one can find a solution, I may have to do it that way.
-----------------------
I pity the foo.
-Mr. T
|
|
|
|
|
I just cant' get how to draw strings with "proper" letter spacing,
especially when they're bold. Some letters in specific combinations
when being drawn next to each other appear slured (without even a pixel gap).
The font I'm using is the default MS Sans Serif 8,25pt
Here's a link to a sample screenshot:
>> link
The left one is drawn using the Graphics.DrawString method and the right one is
a screenshot from a ListView. Why is that difference?
How to achieve this?
|
|
|
|
|
iliyang wrote:
How to achieve this?
May be you must change the StringFormat class ?
|
|
|
|
|
Well, turns out that it is a global issue and there's no way
(at least that I know) that can fix this. Thе string that I
drew was something like "bla bla the_messed_part" (1) and the string
in the listview was "the_messed_part" (2). And when I tried to
draw the string (2) or let the listview draw the string (1)
both work the same way. So I guess the solution is to choose
a different font like Tahoma, for example, which looks like MS Sans Serif.
Of course, this is not a very good solution, 'cause this way I'm
fixing the font and if the user has a totally different system font
set, it'll be pretty ugly...
|
|
|
|
|
I have successfully written a C++ DLL and can pass integer types from C++ to C# using the DllImport method. However I can not figure out how to pass a string (byte array or any other type) from my C++ dll to C#.
The C++ DLL side compiles without error and creates a DLL file. The C# side produces compiler errors no matter how I try to pass the string (have tried everything I can think of). Since Interoperation is a
"virtue" in Visual Studio I am sure that there is a simple solution but it eludes me. Here are the relevant code sections:
In C++ DLL header (.h)
extern "C" __declspec(dllexport) int addfive(int x);
extern "C" __declspec(dllexport) char* putFolderList();
In C++ DLL source (.cpp)
int addfive(int i) { return i+5 ;}
char* putFolderList(){ return "my string" ;}
In C#:
using System.Runtime.InteropServices;
[DllImport("DLLBuildTest.dll")]
static extern int addfive(int x); // VALID
static extern char* putFolderList(); // NOT Valid
errors (2) and warnings (1) from C# compilation:
#1 - warning CS0626: Method, operator, or accessor 'DLLCaller.Form1.putFolderList()' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation
@2 - error CS0214: Pointers may only be used in an unsafe context
#3 - error CS0029: Cannot implicitly convert type 'char*' to 'string'
My question is: What is a valid method for passing a string from a C++ DLL to a C# program?
Paul Largent
|
|
|
|
|
Doesn't
static extern string putFolderList();
help?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I've created a TreeView which lists items from active directory. With the help of another Code Project user, I've created a context menu which is specific to the type of object right-clicked-on by the user.
The problem is that when I select the menu option, the 'sender' holds a reference to the MenuItem, not the TreeNode clicked-on in the first place.
How can I get a reference to the original TreeNode that the user right-clicked on?
I've thought of one way but it seems a bit of a botch: to create a TaggedMenuItem class inherited from MenuItem which has a 'Tag' like Controls have and to use the MouseUp event and populate the Tag of EVERY TaggedMenuItem on the context menu with a reference to the TreeNode as I create the context menu. Then, I can get back to it from the menu item click event handler. Like I said, this sounds a bit crap.
Is there a better way?
|
|
|
|
|
You can subscribe to the MouseDown event and figure out which node was right-clicked on with the help of the mouse coordinates.
Point point = new Point(e.X, e.Y);
TreeNode node = feedTreeView.GetNodeAt(point);
You can then store node in a class level member variable, which you can then access from anywhere within the class.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks for your suggestion. I'm new to OO and I think I was just over-complicating things!
Regards
SH
|
|
|
|
|
How does a HashTable stores data ? it stores inside itself or a HashTable stores only the adress of the object ?
Thanks
|
|
|
|
|
If you store reference types, it stores only references (adresses). If you store value types, I belive it stores values (copies).
David
"Stay Kul And Happy" I.A.
|
|
|
|
|
Only the reference are stored. Not just Hashtable, but any collection stores only references to the objects and not the objects themselves. For value types, the value is boxed and a reference to the boxed instance is stored.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello! I've got a problem.
I've created a class who herits from Hashtable. I've also created a UIEditor to edit the values at design time. But when i do that, there is nothing writed in the InitializeComponent method. My class is however marked as Serializable...
Thanks for your help
|
|
|
|
|
I have a panel with AutoScroll property set to true. the panel contains a picturebox, whose height and width r decided at runtime. Panel's height and width r fixed. When i drag mouse over the picturebox i need the panel to scroll up down right left if the size of the picturebox is greater then the panel. How do i do it?
Thanks in advance
Nitin
|
|
|
|
|
Not bug free, but it gives you an idea
Private _mouseDown As Boolean<br />
Private _lastY As Integer<br />
<br />
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown<br />
_mouseDown = True<br />
_lastY = e.Y<br />
End Sub<br />
<br />
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove<br />
If _mouseDown Then<br />
Dim y As Integer<br />
If e.Y > _lastY Then<br />
y = e.Y - _lastY<br />
Panel1.AutoScrollPosition = New Point(Panel1.AutoScrollPosition.X, y)<br />
ElseIf e.Y < _lastY Then<br />
y = _lastY - e.Y<br />
Panel1.AutoScrollPosition = New Point(Panel1.AutoScrollPosition.X, y)<br />
End If<br />
End If<br />
End Sub<br />
<br />
Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp<br />
_mouseDown = False<br />
End Sub
|
|
|
|
|
Hi,
I need help!
I need to move print job from printer A to Printer B..
my problem is:
I have print's line job and I need to move this to other printers...
How to do it in C#?
please, somebody to know and it will be able to help me...
thank you
|
|
|
|
|
I certainly hope that all of your printers are the same, or at least can use the same printer driver.
You can't move a job from one printer to another. But, you can setup printer pooling so more than one printer can pull jobs from the same queue.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|