|
BTW:
shiftwik wrote: with C# it call delete for you
No, it doesn't - it calls Dispose for you, but not at a time of your chosing, unless you specifically add a using block: objects are only ever deleted when the Garbage Collector gets around to it, which may never happen!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Dispose will only ever be called at a time of your choosing - either from the end of a using block, or when you explicitly call it.
It's the finalizer - ~ClassName(){ ... } - that gets called by the GC at some random time in the future.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes, you are right - and the finalizer should call Dispose(false)...
I plead stupidity...and a lack of caffeine.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Should call Dispose if you are implementing the IDisposable Interface
You usually only use it to ensure that unmanaged resources are released, to prevent memory leaks. Either immediatly when Dispose gets called or when the GC calls the Finalize Method (which you have to override in that case), in case it didn't get called by the code which held the reference to it.
You might also use it to free resources before the GC kicks in (by setting large fields like lists etc. to null and thus making it easier for the GC to collect those resources).
|
|
|
|
|
Nicholas Marty wrote: Should call Dispose if you are implementing the IDisposable Interface
If your class has a finalizer and doesn't implement IDisposable , that's almost certainly a bug.
I can't think of any reason why your class would say, "I want this resource to possibly be cleaned up at some unknown point in the future, but I don't want the calling code to be able to clean it up immediately".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Every Type has a finalizer as every object inherits from System.Object at some point. You may or may not override it. But it still has a finalizer
|
|
|
|
|
The Object class provides no implementation for the Finalize method, and the garbage collector does not mark types derived from Object for finalization unless they override the Finalize method.
So whilst it's technically true that every object has a finalizer, only objects which override the finalizer will be marked for finalization.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yeah. And you should suppress the finalization of the object if you disposed the object already
And yeah, if you override the finalizer you should probably also use the IDisposable pattern.
|
|
|
|
|
2. You could do something like this:
public int LimitedInt{
get{
if(mylimitedint < 0){
limitedint = 0;
}
if(limitedint > 42){
limitedint = 42;
}
return limitedint;
}
}
3. Yes everything that has something to do with the OS will pass through the kernel, but it passes through the .NET framework first. IOW the framework adds functionality to your code. Among many things Garbage Collection, Exception handling etc ...
|
|
|
|
|
Hi, i am reading a C# book call C# for students by Douglas Bell & Mike Parr
if anyone have the code of that book please i need your help if you can send it to me
Thank you
|
|
|
|
|
The link address for the code is usually printed somewhere in the book, try the inside covers, or any appendices.
|
|
|
|
|
Took me one search in Google to find this[^].
|
|
|
|
|
|
|
Good Morning,
i need your help
let say i want to write a program to adjust one side of a rectangle
with a track bar how can i do that?
thank you
|
|
|
|
|
hi I am getting an error message: Connot implicitly type 'void' to 'string'
here is the code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] strings = { "man", "bites", "mad", "dog" };
dataTextBox.Text = (Permute(strings, Output));
strings[0] = indexTextBox.Text;
strings[1] = indexTextBox.Text;
strings[2] = indexTextBox.Text;
strings[3] = indexTextBox.Text;
}
private void Output(T[] permutation)
{
string data;
data = dataTextBox.Text;
foreach (T item in permutation)
{
dataTextBox.Text = Convert.ToString (item);
}
}
public static void Permute(T[] items, Action output)
{
Permute(items, 0, new T[items.Length], new bool[items.Length], output);
}
private static void Permute(T[] items, int item, T[] permutation, bool[] used, Action output)
{
for (int i = 0; i < items.Length; ++i)
{
if (!used[i])
{
used[i] = true;
permutation[item] = items[i];
if (item < (items.Length - 1))
{
Permute(items, item + 1, permutation, used, output);
}
else
{
output(permutation);
}
used[i] = false;
}
}
}
}
|
|
|
|
|
The reason you are seeing this is because you are trying to assign the output from Permute to the Text property. Permute is a void property, so it cannot return anything.
|
|
|
|
|
Hi what come I do to fixe that
|
|
|
|
|
Return a string value where you have it set to void and actually set it to a meaningful value. This is basic stuff, you should be able to do this already.
|
|
|
|
|
|
Below code works well for printing PDF when we have physical file.
But when we have bytes[] then it will not work. Is there a way we can print bytes[] to printer without showing the print dialog box.
private static void PrintPDF(string FileToPrint)
{
PrinterSettings setting = new PrinterSettings();
var printerName = setting.PrinterName;
ProcessStartInfo info = new ProcessStartInfo(FileToPrint);
info.Verb = "Print";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
}
There is a Microsoft Knowledge base article on this particular problem. Here in the article they send byte[] to the printer using Winspool API of Windows OS. but i don't feel it is optimized for web.
http://support.microsoft.com/kb/322091
|
|
|
|
|
What all this has with the Web?
The code you show us here is part of the server side, means it print on the printer connected to the server? It may looks like working correctly while in debug environment, but will surprise you after publishing? Or do you mean to post out all the printed documents later on the week?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
The code given works well with physcial files
I meant the KB article that code i dont feel is optimized
|
|
|
|
|
It seem that you didn't read or understood what I've wrote...
That code - and your code too - can not be, and need not be optimized to the web as it runs on the server!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Since it runs on server my only concern is when i run it to print too many pdf t slows down when multiple requests are hit.
If there a better way of printing bytes[] to printer
|
|
|
|