V
Vibhesh
I am facing problem with TimeSpan structure when DirectX is used.
Following is the sample code that causes the problem:
***************************************************************************************************************
{
...........................
PrintTimeSpanProblem();
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
PrintTimeSpanProblem();
..............
}
public void TimeSpanProblem()
{
DateTime dt1970 = new DateTime(1970, 1, 1);
TimeSpan tss = DateTime.Now - dt1970;
uint nT11 = (uint)(tss.Ticks / TimeSpan.TicksPerSecond);
uint nT1 = (uint)tss.TotalSeconds;
uint nT2 = (uint)(tss.Ticks - (nT1 * TimeSpan.TicksPerSecond));
//Ideally nT11 and nT1 should be the same.
//After new Device is created, TimeSpan.TotalSeconds does not give
correct value.
if (nT1 != nT11)
{
Debug.WriteLine("********************************************************"
+ "\nPROBLEM!!"
+
"\n********************************************************"
+ "\nTicks =" + tss.Ticks.ToString()
+ "\nTotalSeconds(T1) =" + nT1
+ "\nT2 =" + nT2
+ "\nTicks/TicksPerSecond(T11)=" + nT11
+
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else
{
Debug.WriteLine("********************************************************"
+ "\nEverything OK!!"
+
"\n********************************************************"
+ "\nTicks =" + tss.Ticks.ToString()
+ "\nTotalSeconds(T1) =" + nT1
+ "\nT2 =" + nT2
+ "\nTicks/TicksPerSecond(T11)=" + nT11
+
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
}
***************************************************************************************************************
In normal case (i.e. when TimeSpan behaves correctly), following would
be the output:
ts.Ticks =11792483786198544
nT1 =1179248378
nT2 =6198544
nT11 =1179248378
Note that, nT1 is first 10 digits of ts.Ticks, and nT2 is last 7
digits of ts.Ticks
After new Device(..) is getting called the output is following:
ts.Ticks =11792499480265504
nT1 =1179249920
nT2 =280265504
nT11 =1179249948
Note that, nT1 is not same as first 10 digits of ts.Ticks, and nT2 is
9 digits long and is not same as last 7 digits of ts.Ticks
THIS MEANS THAT VALUE OF ts.TotalSeconds DOES NOT CORRESPOND TO THE
VALUE OF ts.Ticks.
Please let me know if anyone of you have faced such a problem?
Regards,
Vibhesh.
Following is the sample code that causes the problem:
***************************************************************************************************************
{
...........................
PrintTimeSpanProblem();
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
PrintTimeSpanProblem();
..............
}
public void TimeSpanProblem()
{
DateTime dt1970 = new DateTime(1970, 1, 1);
TimeSpan tss = DateTime.Now - dt1970;
uint nT11 = (uint)(tss.Ticks / TimeSpan.TicksPerSecond);
uint nT1 = (uint)tss.TotalSeconds;
uint nT2 = (uint)(tss.Ticks - (nT1 * TimeSpan.TicksPerSecond));
//Ideally nT11 and nT1 should be the same.
//After new Device is created, TimeSpan.TotalSeconds does not give
correct value.
if (nT1 != nT11)
{
Debug.WriteLine("********************************************************"
+ "\nPROBLEM!!"
+
"\n********************************************************"
+ "\nTicks =" + tss.Ticks.ToString()
+ "\nTotalSeconds(T1) =" + nT1
+ "\nT2 =" + nT2
+ "\nTicks/TicksPerSecond(T11)=" + nT11
+
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
else
{
Debug.WriteLine("********************************************************"
+ "\nEverything OK!!"
+
"\n********************************************************"
+ "\nTicks =" + tss.Ticks.ToString()
+ "\nTotalSeconds(T1) =" + nT1
+ "\nT2 =" + nT2
+ "\nTicks/TicksPerSecond(T11)=" + nT11
+
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
}
***************************************************************************************************************
In normal case (i.e. when TimeSpan behaves correctly), following would
be the output:
ts.Ticks =11792483786198544
nT1 =1179248378
nT2 =6198544
nT11 =1179248378
Note that, nT1 is first 10 digits of ts.Ticks, and nT2 is last 7
digits of ts.Ticks
After new Device(..) is getting called the output is following:
ts.Ticks =11792499480265504
nT1 =1179249920
nT2 =280265504
nT11 =1179249948
Note that, nT1 is not same as first 10 digits of ts.Ticks, and nT2 is
9 digits long and is not same as last 7 digits of ts.Ticks
THIS MEANS THAT VALUE OF ts.TotalSeconds DOES NOT CORRESPOND TO THE
VALUE OF ts.Ticks.
Please let me know if anyone of you have faced such a problem?
Regards,
Vibhesh.