|
I Try this ..
-- Example C#:
long lInit, lDiff;
//Start function
lInit = DateTime.Now.Ticks;
//Event timer (interval 1 millisecond)
lDiff = (DateTime.Now.Ticks - lInit) / 1000;
But the result is different from example below:
-- Example VB6:
//Start function
lInit = GetTickCount()
//Event timer (interval 1 millisecond)
lDiff = (GetTickCount() - lInit) / 1000
I must view any millisecond elapsed on interval ...
Alex
|
|
|
|
|
The Ticks property returns the number of 100-Nanosecond-Intervals since a specific date, so you should divide by 10000 I think.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I have tried but it does not work correctly…
Alex
|
|
|
|
|
AlexB47 wrote: does not work correctly…
What does that mean? How does the calculation results differ?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
every elapsed time (1 millisecond) show this ...
//1 second elapsed
10000
//another second elapsed
20000
//another second elapsed ..
30000
...
Alex
|
|
|
|
|
Where is the big problem? The values look quite good with the exception that obviously the unit doesn't fit. So simply increase the divisor (multiply with 10) in your calculation.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
The answers is System.Environment.TickCount ..
|
|
|
|
|
You may get diasppointed here: all timing information has some resolution and
some accuracy, and in general accuracy is much worse than resolution may suggest.
Try the following code on your system:
public override void Run() {
long t1=DateTime.Now.Ticks;
int count=0;
int tries=0;
while(count<20) {
tries++;
long t2=DateTime.Now.Ticks;
long diff=t2-t1;
if (diff!=0) {
log("tries="+tries+" t1="+t1+" t2="+t2+" diff="+(t2-t1));
count++;
t1=t2;
}
}
}
You will notice that most of the time diff=0 (suggesting a really fast machine!)
and sometimes diff is something else, typically equal to (or a multiple of)
the real smallest time step you can measure in this way (on my PC it is 156250,
which corresponds to 1/64 second). So dont expect to construct a millisecond chrono
out of it.
What you do need is good old PInvoke to the PerformanceCounter stuff.
Luc Pattyn
|
|
|
|
|
We proceed for small steps… why in .NET 2.0 framework an instruction as under brought back SHOW the millisecond and in framework .NET 2.0 CF (same function, identical code) the millisecond do not SHOW? I have tried also with the Application.DoEvents but nothing ... why?
Es..
private long m_lInitialTick;
private void StartCrono()
{
m_lInitialTick = DateTime.Now.Ticks;
timerTmp.Interval = 1;
timerTmp.Enabled = true;
}
private void StopCrono()
{
timerTmp.Enabled = false;
}
private void timerTmp_Tick(object sender, EventArgs e)
{
label.Text = Convert.ToString((DateTime.Now.Ticks - m_lInitialTick) / 10000) ;
}
|
|
|
|
|
You should read my previous post again,
then try my code snippet on your system.
It would be completely wrong to expect DateTime.Ticks to increment by 1,
on my system it increments by 156250, and maybe on a portable system
it increments by 10000000 (maybe there is only one clock tick per second "to preserve power").
There is nothing in the MSDN help that specifies one or the other; this is unfortunate.
If you have any kind of performance counter available (maybe the one in .NET 2.0,
otherwise the native Win32 one), then that one will give you the best results.
I do not know whether .NET Compact is capable of handling sub-second intervals, I hope it does.
Luc Pattyn
|
|
|
|
|
Dear Sirs,
I use Visual Studio .NET 2005 (Framework 2.0)
I use Tree-Tier architecture approach in my project, and I use NHibernate.
I get data in the Data Layer from database and initialize object.
In View Layer;
First of all I determine ValueMember and DisplayMember for ComboBox
comboBox1.ValueMember = "id";
comboBox1.DisplayMember = "name";
And determine DataSource for ComboBox. I get data in IList fromat from Data Layer.
comboBox1.DataSource = XYZ; //XYZ is a IList
Now, ComboBox list name, its OK. My problem is I get id when I select any name from combobox.
**FOR EXAMPLE:
TEST_TABLE
ID Name Surname
-- ---- -------
3 Jack Black
4 Marry Green
5 John Wall
I fill combobox like this;
comboBox1.ValueMember = "id";
comboBox1.DisplayMember = "name";
comboBox1.DataSource = obj; //obj is IList
So, combobox filled and show "Name"s.
How can I get selected value's ID from combobox.
For example, if I select "Marry" on the combobox, how can I get "4"?
Note: This ways not solve my problem.
int i = int.Parse(comboBox1.SelectedValue.ToString()); //ERROR: Input string was not in a correct format.
Int32 i = Convert.ToInt32(comboBox1.SelectedValue); //ERROR: Unable to cast object of type 'NAMESPACE.CLASSNAME' to type 'System.IConvertible'.
Int32 i = (Int32)comboBox1.SelectedValue; //ERROR: Specified cast is not valid.
int i = (int)comboBox1.SelectedValue; //ERROR: Specified cast is not valid.
string test = (string)comboBox1.SelectedValue; //ERROR: Unable to cast object of type 'NAMESPACE.CLASSNAME' to type 'System.String'.
string test = comboBox1.SelectedItem.ToString(); //RETURN: 'NAMESPACE.CLASSNAME'
DataRowView o = (DataRowView)comboBox1.SelectedValue; //ERROR: Unable to cast object of type 'NAMESPACE.CLASSNAME' to type 'System.Data.DataRowView'.
object o = comboBox1.SelectedValue;
int i = Convert.ToInt32(o); //Unable to cast object of type 'NAMESPACE.CLASSNAME' to type 'System.IConvertible'.
Best Regards...
-- modified at 4:21 Friday 26th January, 2007
|
|
|
|
|
mmmh...
The DataSource of your ComboBox has which Type?
An ArrayList with Class-Instances who represent via there Members ( via Get&Set ) the DataBase-Elements?
Or is it a DataTable ?
In VS.NET 2003 it exists a CurrencyManager. That's a "pointer" on a DataTable, which is pointing on the current Row. I don't think that a ChangeSelection of the ComboBox also changes the "current marked Record-Row" ... but it's a possibility to check if you find no way to resolve it.
Another Possibility is to make a relation between your ComboBox and your IList-Objekt.
If the indices of each are the same, you can get the SelectedIndex from the ComboBox:
In this case "1" .. than you go to the IList at index "1" and extract the "ID-Field"
I hope this helps you maybe.
Greetings
|
|
|
|
|
I don't fully understand the new keyword. For instance, I am creating an OdbcCommand object:
<br />
OdbcCommand command = new OdbcCommand(statement, connection);<br />
Now I use the command, and then want to change it later. Should I use the new keyword again? Could I just say:
<br />
command = OdbcCommand(newStatement, connection);<br />
And if I do need to use the new keyword there, does it just leave the old object hanging out there to be cleaned up by the CLR later?
|
|
|
|
|
Hello,
"new" always creates a new instance of an object (type);
So If you need to change something and it's not possible over properties, you have to create a new instance of this class.
This also means that you have two instances in the memory but only one referenced to youre local variable (command).
The GarbadgeCollector is not always able, per default, to clear this memory. (reference could be hold from an other class over an eventhandler)
If the class is a member of IDisposable, you should call the Dispose method first.
Loophole wrote: command = OdbcCommand(newStatement, connection);
This will not compile, unless the Constructor requires the new keyword.
All the best,
Martin
|
|
|
|
|
Thanks, I guess I'm just making it more complicated in my head than it is.
|
|
|
|
|
Before asking this kind of (stupid) question you could try it yourself. If you had, you would realize that your suggestion is not even possible to compile, hence the "new" keyword (even if you do not "fully understand" it) is necessary.
Internet - the worlds biggest dictionary
|
|
|
|
|
Wow!
You really must have a bad day!
Try it with joga!
But dont't mind, weekend is coming!
|
|
|
|
|
Thanks buddy. Obviously the point of my question was to understand how the new keyword works in general, not just to get my code working in this particular instance. I searched for info on the worlds biggest 'dictionary,' and the way the new keyword is explained is the same almost everywhere. I didn't quite get it, so I was looking for a different perspective. Also, your mom.
|
|
|
|
|
Sorry, I was being a bit more grumpy than needed. My mom
Internet - the worlds biggest dictionary
|
|
|
|
|
Loophole wrote: And if I do need to use the new keyword there, does it just leave the old object hanging out there to be cleaned up by the CLR later?
Yes, and if you do this and the object has a Dispose method, you should call that first.
Loophole wrote: command = OdbcCommand(newStatement, connection);
You obviously still need the 'new' keyword in this instance.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
i have two forms ie, Form1 and Form2. Form1 contains a Button Control.
i have write code in Button of Form1 to Open Form2. Problem is that when each time i click button of Form1 it Opens new Form2. How to Control that? if Form2 is open it should not be open again.
privete ..Button1_Click(....)
{
Form2 objFrm=new Form2()
objFrm.Show()
//objFrm.ShowDialog();
}
Sanjit.rajbanshi@wlinktech.com
|
|
|
|
|
You can try o check if the Form2.visible = false and only then show the Form2, else do nothing
|
|
|
|
|
Hello,
One posibility would be:
Hold the instance of the Form2 class lokal in Form1.
private Form2 objFrm2;
in your Button Click event:
private void button1_Click(object sender, System.EventArgs e)
{
if(objFrm2==null)
{
objFrm2 = new Form2();
objFrm2.Closed+=new EventHandler(objFrm2_Closed);
objFrm2.Show();
}
else
{
objFrm2.BringToFront();
}
}
private void objFrm2_Closed(object sender, EventArgs e)
{
objFrm2 = null;
}
Hope that helps!
All the best,
Martin
|
|
|
|
|
Thanks! it is working
Sanjit.rajbanshi@wlinktech.com
|
|
|
|
|