|
Thanks for a great answer,
The UserControl s used in the application host a number of other controls, grids, UserConrols etc.
In addition to these the UserControl s also has some DataSet s which are bound to the UI controls. I've written code for disposing the resources used by the user control by overrinding the Dispose method of the UserControl . Is it necessary to explicity dispose of all Control s being used by the host control? All these conrols implement the IDisposable interface. Either way I still have a memory leak although I've tried to clean up my act.
When the main application window is minimized I notice that the resources used by the application is freed and that the memory usage drops down to a reasonable amount. Has anyone got a short explanation for this? Is there a way to do this without having to minimize the window?
Magnus Green
|
|
|
|
|
Almost any time you override a method you must call it's base implementation. This is especially true in the case of overriding Dispose(bool) , inheritted from Component . If you don't, the class members you don't free that either Component , Control , or any other derivatives know about won't be freed.
Again, though, you do not need to explicitly dispose Component s or its derivatives. They are designed so that you don't have to and it is recommend that you don't.
And of course all controls implement IDisposable - they inherit it from Component .
Why does memory drop when you minimize the application? If you read some of the links I gave you, you'd see that the GC runs when the application is idle or when memory is required and objects are available for GC'ing. When you minimize an application, it is considered idle because it does not receive user input (it may still be doing work, but only in the background).
As I hinted at before, you can call GC.Collect but this is highly not recommended because it can cause serious performance problems for your application. The fundamental problem here is your current design: either too many controls or you're not freeing everything you think you're freeing (and because you override Dispose(bool) you're not responsible for freeing everything, especially if you're not calling base.Dispose(bool) in your override).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi all,
This has probably been posted before but...
How do i remove the cross from the top right of a form.
I don't want the user to be able to close the form this way.
Cheers
Kev
|
|
|
|
|
Set MinimizeBox, MaximizeBox, and ControlBox to false.
--
Joel Lucsy
|
|
|
|
|
I can't, i need the user to be able to minimise the application as when they do this the application goes to the system tray instead of the task bar.
Kev
|
|
|
|
|
Then you're going to have to take a different approach. Windows itself requires a close box if either minimize or maximize is present.
Another method is to use the handler on the form for Closing. This will give you a change to say "no" and abort the close.
You'll get something like:
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
where you can say:
e.Cancel = true;
--
Joel Lucsy
|
|
|
|
|
I am already doing that.
I was trying to restrict the cross being clicked, i suppose i could have a Hide button that set notifyIcon.Visible to true and hides the form.
Will give it a go anyways.
Cheers
Kev
|
|
|
|
|
|
That doesn't link to anything related to this topic
Kev
|
|
|
|
|
|
That would work but i would still need to stop alt + F4
Kev
|
|
|
|
|
Therefor write an event handler for the close event of your form and simply cancel the event.
To assure you could still close your form, you could declare a bool which will be set before you programmatically close your form and then will be checked inside the event handler.
www.troschuetz.de
|
|
|
|
|
Let me explain what i'm trying to do and maybe you can advise me.
I have written a scheduler application that we will have running on 67 remote PC's based in the back offices of our shops, most of the shop staff don't know the difference between a monitor and a PC so we have to restrict what they are allowed to do.
The scheduler application will run in the system tray while the user is logged on. On occasion one of our support guys may need to shut the scheduler down remotely wihtout logging the user off. To allow this, and to prevent the user from shutting the scheduler down accidentaly, i have hard coded a password into the assembly.
The support guys all know the password so they can shut the app down without a problem, it runs in the system tray fine. My problem is, if the user wants to restart the pc, sometimes they need to do this, the application is prompting for a password and then coming up with the program not responding dialogue box.
I'm trying to make it so if the user logs off / shuts the pc down the app saves itself and closes gracefully. I was hoping to use a button to exit the program, that way i could check the password in the button click and then call form.Close().
To be able to do that however i need to do 2 things.
1. Disable the cross on the form.
2. Disabel the Alt + F4 shortcut.
This way the only way the program could be shut down would be by clicking the button and entering the password or by logging off / Shutting the pc down.
Hope that makes sense, do you have any ideas?
Cheers
Kev
|
|
|
|
|
I see the point.
exhaulted wrote:
To be able to do that however i need to do 2 things.
1. Disable the cross on the form.
2. Disabel the Alt + F4 shortcut.
I hope number 1 can be solved nice with the answer given in thread I linked to. If not we solve it the same as number 2.
As I already said the easiest way would be declaring a private bool in your form which then will be checked inside the event handler for the closing event.
For example the bool is initialized false and in this case the event handler cancels the Closing event. The only way to set this bool true is clicking the button, you mentioned, and entering the right password.
class YourForm
{
private bool shutDown = false;
void button_click(...)
{
if (passwordCorrect == true)
{
shutDown = true;
this.Close;
}
}
void form_Closing(...)
{
if (!shutDown)
e.Cancel = true;
}
}
This leaves us with the problem of shutting down / logging off. Don't know a exact solution for this one. Maybe you could use the sender object, you receive with the form_Closing event handler, to determine whether the close event was triggered by one of those events.
P.S: The code snippet should only concretize what I'm talking about. Doesn't spend much time to bring it into right syntax.
www.troschuetz.de
|
|
|
|
|
I can get round everything except the shutting down / log off without any complicated code.
Form_Close()
{
e.Cancel = CheckPassword();
}
This way i can leave the cross on the form and only users that know the password can shut the app down. Still stuck with the logging off bit though!
Anyway, thanks for all your help. If i figure it out i'll let you know.
Kev
|
|
|
|
|
I like this one. Simplyfies the whole thing
Also good luck with the unsolved problem.
www.troschuetz.de
|
|
|
|
|
http://www.experts-exchange.com/Programming/Q_21801324.html
add this function to disable "Close Box" as well as "Alt + F4"
protected override CreateParams CreateParams
{
get
{
const int CS_NOCLOSE = 0x200;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_NOCLOSE;
return cp;
}
}
|
|
|
|
|
Folks,
I am working on a Web-Application that will run on my company's Intranet, to gather DIT File data from the domain controllers (>160 DC's total), and display that data in a DataGrid (Columns: DC Name, Baseline, Request2, Request1, CurrentRequest). The web-app is being written in C# and the data will reside in a SQL2000 Database.
Pelase bear with me as ALL of my programming knowledge is self-taught. As such, I want to be sure I don't fall prey to writing code that is NOT secure or is a "bad practice."
My question is this: What is considered the "Best Practice" for gathering this type of information from a DC? Is a Web-Service better or would it be more secure to utilize a Stored Procedure? (Note: The application will ONLY be used by authorized personnel [a tie into AD for authentication will be written] internally).
Any thoughts, suggestions or comments are very much appreciated and welcomed.
Cordially,
- - -
KoalaCowboy
Seeker of Knowledge
|
|
|
|
|
An XML Web Service is in no relation to stored procedures. They do entirely different things and can be used together or apart.
A stored procedure is simply a procedure implemented in a Relational Database Management System (RDBMS). It gives you flexibility of separating logic from data (the stored procs and data could even exist on separate RDBMSs) and implementing complex procedures that would otherwise be problematic in code (coding SQL commands in your code makes your compilations less robust).
XML Web Services describe a standard whereby a common format (SOAP, an XML "grammar", or schema) is sent over HTTP or HTTPS. An XML Web Service that queries data could use stored procs to read/write data, or something not even related to data.
The question you have to ask yourself is about architecture first. Do you need to go across disparate networks (like a WAN)? Do you need to support many different types of clients (written in, perhaps, many different languages and on different platforms)? If yes to either, then Web Services might be your answer. That still doesn't rule out stored procedures, though.
Regarding stored procedures, do you want to support complex queries? Do you want to maintain robust code? If yes to either of those, then using stored procs is probably your best bet (and I honestly can't think of too many reasons for not using stored procs if even one of your queries is just more than a simple, single SQL command).
With regard to security, it is different questions you must ask yourself. If you do use XML Web Services and need to protect data across the wire, then you should use HTTPS instead of HTTP (HTTPS is HTTP over SSL, an encryption algorithm). You could also use WS-Security standards that you can read about on http://msdn.microsoft.com/webservices/building/wse/[^], as well as download the Web Service Enhancements from Microsoft which impements these common standards (please note that while Microsoft is a major player in defining these standards, there is a consortium of vendors like IBM and others. The WSE is just Microsoft's implementation of WS standards, just like .NET is Microsoft's implementation of the Common Language Infrastructure, or CLI).
If you're using stored procedures, you should use role-based authentication and authorization in the RDBMS. SQL Server supports this, as well as others. Don't just accept the default authorization and permissions.
There's so much more when dealing with security and robust code. If you need information on either subject, I recommend reading some of the many great and FREE online books (you can also order print editions) at http://msdn.microsoft.com/patterns[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath,
First and foremost, thank you for the very well written response!
More detail is in order, so as to ellicit more knowledge:
We currently have >160 DC's, spread out all over the globe. The initial phase of my project will include only the US based DC's (>130), which are connected via multiple WAN links (redundancy via routed network).
The data that I am trying to acquire is merely the DIT File size for each DC. I would like to have a "scheduled task" that grabs that data and inserts the file size & time into a SQL 2000 DB. The task will be run every 3 hours from 8am Eastern to 11pm Eastern and the data will be displayed in an C# DataGrid (DC Name, Baseline, 2nd oldest data, 1st oldest data, most recent data).
Based on the above information, what makes the most sense for data acquisition and population into the database?
Thanks again for your knowledge and guidance!
Cordially,
- - -
KoalaCowboy
Knowledge Monger
|
|
|
|
|
While this has extended well beyond a C# question, I will answer this once.
I personally would use MSMQ (Microsoft Message Queue) where each DC posts a message containing the data you need to a queue asynchronously. Why go to the overhead of a request/response mechanism when it's not needed (HTTP is, by protocol, a client request/server response protocol).
The listener on the queue takes this information and posts it in SQL Server using a simple SqlCommand . Use a stored procedure to separate logic and abstract your implementation so that you can change a small piece without recompiling and testing the whole solution (modularize).
The .NET Framework supports MSMQ in the System.Messaging [^] namespace, which you can read about in the .NET Framework SDK. The documentations includes many examples.
Note that the MSMQ server can be installed on Windows 2000 (Workstation and Server), XP (Professional), and 2003. It is not typically installed by default.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath,
Thank you for the pointed information! Lots of reading ahead.
Regards,
KoalaCowboy
Knowledge Monger
|
|
|
|
|
i have a pool of threads (max is 20), what they do is every so often (at the moment its every second) they monitor an inbox (email) for new emails and if it finds one it processes it!!!
however i know need to incorporate a new requirement which introduces a time delay ie poll an inbox for new emails on the first of every month, or every day/hour or every 3rd week of the month.
now if i use a threadpool (max of concurrent threads is 20) i could have a thread sat on there till the first of the month waiting to be executed doing nothing, therefore preventing other threads from getting executed. the question then is "Now how can u monitor multiple inboxes using threadpools (or somethign else for that matter), for new emails , which would allow u to include a time delay and not have a big effect on CPU processing or on the overall performance of the architecture?"
any ideas would be welcome, this has been bashing my head for days
|
|
|
|
|
hi,
i'd like to write a control.name to a text file during designtime.
i cant find a property or function like "OnNameChanged" or something like that.
is there any idea to solve this problem.
background is to localize a project. i'm using global an local resources.
during designtime i'd like to write the names of the control to my local resx(txt).
if localization is enabled in the form, VS writes the changed name in the resx owned by the form. the same i'd like do to with my local.resx during designtime. at the moment only with the control.name.
at the moment i have a LocalizedButton derived fom Button.
How is it possible to write the changed name during designtime to a txt file?
hope someone knows what i mean......
greetz
|
|
|
|
|
hi,
You can monitor the chages provided you need to go for a custom event.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|