|
Doesn't DateTime.Now.AddHours(-24) looks cleaner?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thanks a lot.
I didn't know it
|
|
|
|
|
d@nish wrote: Doesn't DateTime.Now.AddHours(-24) looks cleaner?
IMO the logical approach would be DateTime.Now.AddDays(-1)
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Especially since subtracting hours may not work on days with leap seconds or 25 hours.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: Especially since subtracting hours may not work on days with leap seconds or 25 hours.
There are no days with 25 hours, only ones with 24.
|
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: A correctly implemented DateTime class should require subtracting 25 hours on the switchover date or 23 depending on the Calender. Which is why one should subtract days and not hours.
I wish I had a dollar for every time I've been through this argument. The clocks on computers use UTC (Universal Co-ordinated Time) based on what was Greenwich Mean Time, but is now agreed by one of the UN bodies. For argument's sake it is as near to GMT as makes no difference. When you want to display the time then the library routines make an adjustment based on the local timezone and the rules for daylight saving time appropriate to that timezone. However all DateTime calculations are based on UTC so there are never any discrepancies such as you imagine; every day is 24 hours long, whatever the time of year. Only in this way can date and time calculations work correctly.
|
|
|
|
|
My original comment was in jest suggesting that a good programmer would subtract a day instead of 24 hours; hoping that the parody would drive the point home. My reply to you was to point out that it is entirely possible to come across a 23 or 25 hour day in an implementation. Of course, your reply will once again ignore the point I was trying to make so I don't know why I bother.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: My original comment was in jest suggesting that a good programmer would subtract a day instead of 24 hours; hoping that the parody would drive the point home.
Your original comment: Especially since subtracting hours may not work on days with leap seconds or 25 hours.
Spot the humour? Well I didn't.
Ennis Ray Lynch, Jr. wrote: My reply to you was to point out that it is entirely possible to come across a 23 or 25 hour day in an implementation.
Not so, this is what you actually said:
Your reply: A correctly implemented DateTime class should require subtracting 25 hours on the switchover date or 23 depending on the Calender. Which is why one should subtract days and not hours.
No, still can't see either joke or parody.
Ennis Ray Lynch, Jr. wrote: Of course, your reply will once again ignore the point I was trying to make so I don't know why I bother.
As far as I could see, the point you were trying to make was that there are dates in the calendar where a day can equal 23 or 25 hours.
And since you seem to take umbrage when someone misses your hilarious joke, I'm not sure why you bother either.
|
|
|
|
|
True.
On the lighter side, he does not wants the day before but the time 24 hrs less than current time. Hence the reply.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Correct.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
This is a Compact framework question...
I'm building this application that deals with a lot of images coming from the network (~30 k a piece). I am starting to see serious memory issues arise after a while. While my images are mostly cached and the cache is cleaned up if you play with the app for long enough you get an out of memory exception. I can see the app running with up to 25 megabytes of memory in use, the problem is I'm not entirely sure what is causing this. My best guess is that the bitmap caches the decompressed version of the image after its been shown on the picturebox, either that or the picturebox does.
Is there a way to reduce the memory footprint while still having that amount of images (roughly 30) in memory, the only way I can think of is to not put the actual bitmap on the display but rather a copy and after the bitmap has been shown to let the garbage collector handle the copy, however I'm pretty sure that thats going to hurt performance.
Any other idea's?
|
|
|
|
|
You do call Dispose() on images you no longer need, do you?
If that doesn't help, show us some code.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Aurigma.com has an extension to .NET (GraphicsMill) that allows creating and saving TIFF images with LZW compression. Besides saving memory, compression also speeds up loading, saving, and transmitting images.
|
|
|
|
|
Hello,
I have a stream witch are send directly on printer using IP adresse and port, I want to receive this stream ans save it on file : for exemple PCL.
Please help me to resolve this problem. thank you verry mutch.
|
|
|
|
|
hi, I've been trying all the ways to access controls on the mainform from a class but something is missing.By the way, access modifier of the controls I want to access are all Private and I want to access them using public properties and methods. Here is the situation, thanks for your help.
I don't want to make "high coupling", wanna access just a few controls.
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public string buttontext //using either this
{
get { return this.btn1.Text; }
set { this.btn1.Text = value; }
}
public void button1Text(string txt) //or this
{
btn1.Text = txt;
}
}
public partial class masaCubuk : UserControl
{
public masaCubuk()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//accessing with this
MainForm frm = new MainForm();
frm.buttontext="sample";
//or with this
MainForm frm = new MainForm();
frm.button1Text("sample");
}
}
|
|
|
|
|
|
but it is not recommended and I wanna figure out how it is done with public properties and methods
|
|
|
|
|
It's done the same way, but with a property "in between"
|
|
|
|
|
So do it. The property get / set is the way to go, but your code fragment should work, pretty much. You presumably have frm.Show() or frm.ShowDialog() somewhere, so what's the problem?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
there is no frm.Show(), I'm just creating an instance of the mainform and trying to get or set the value of controls on the mainform
|
|
|
|
|
And the code you posted will do that - you just won't see the results if you don't show the form...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
teknolog123 wrote: something is missing
Is this the problem that you need help with? I'm can see a mistake in your code but before I bother typing in a full response can you let us know what issues you are having.
Alan.
|
|
|
|
|
Hi Alan,
briefly, I created a custom control and put it on the main form.During runtime the custom control is doing something and needing to write/change value of the controls on the mainform. This is where I get stuck. All I want is to access and set/get the mainform's control's values through public properties/methods without making their access modifiers public.Please see my first post for the code I use
thanks in advance
|
|
|
|
|
Ok,
I'm still guessing then. The custom control, masaCubuk, is a child of MainForm and I assume that btn1.Text on the visible instance of MainForm never changes.
If that is the issue then the reason the code does not work lies in these lines:
private void button1_Click(object sender, EventArgs e)
{
MainForm frm = new MainForm();
frm.buttontext="sample";
}
Here you intend to communicate with the existing MainForm but have created a new instance. What would be required to get this code fragment to work is a reference to the actual MainForm, i.e. the parent of masaCubuk. You could pass the reference as an argument to masaCubuk's constructor but doing so would introduce the tight coupling that you wish to avoid.
The accepted "loose coupling" technique is to have the main form access the custom control by subscribing to events exposed by the control.
MSDN's How To topic[^]
If you have never written an event this will seem like a lot of work but the code pattern is so standard that once learnt it is easily remembered.
Alan.
|
|
|
|