I am facing problem with TimeSpan structure when DirectX is used.
Following is the sample code that causes the problem:
*************** *************** *************** *************** *************** *************** *************** ******
{
............... ............
PrintTimeSpanPr oblem();
device = new Device(0, DeviceType.Hard ware, this,
CreateFlags.Sof twareVertexProc essing, presentParams);
PrintTimeSpanPr oblem();
..............
}
public void TimeSpanProblem ()
{
DateTime dt1970 = new DateTime(1970, 1, 1);
TimeSpan tss = DateTime.Now - dt1970;
uint nT11 = (uint)(tss.Tick s / TimeSpan.TicksP erSecond);
uint nT1 = (uint)tss.Total Seconds;
uint nT2 = (uint)(tss.Tick s - (nT1 * TimeSpan.TicksP erSecond));
//Ideally nT11 and nT1 should be the same.
//After new Device is created, TimeSpan.TotalS econds does not give
correct value.
if (nT1 != nT11)
{
Debug.WriteLine ("************* *************** *************** *************"
+ "\nPROBLEM! !"
+
"\n************ *************** *************** **************"
+ "\nTicks =" + tss.Ticks.ToStr ing()
+ "\nTotalSeconds (T1) =" + nT1
+ "\nT2 =" + nT2
+ "\nTicks/TicksPerSecond( T11)=" + nT11
+
"\n~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~" );
}
else
{
Debug.WriteLine ("************* *************** *************** *************"
+ "\nEverythi ng OK!!"
+
"\n************ *************** *************** **************"
+ "\nTicks =" + tss.Ticks.ToStr ing()
+ "\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 =11792483786198 544
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 =11792499480265 504
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:
*************** *************** *************** *************** *************** *************** *************** ******
{
............... ............
PrintTimeSpanPr oblem();
device = new Device(0, DeviceType.Hard ware, this,
CreateFlags.Sof twareVertexProc essing, presentParams);
PrintTimeSpanPr oblem();
..............
}
public void TimeSpanProblem ()
{
DateTime dt1970 = new DateTime(1970, 1, 1);
TimeSpan tss = DateTime.Now - dt1970;
uint nT11 = (uint)(tss.Tick s / TimeSpan.TicksP erSecond);
uint nT1 = (uint)tss.Total Seconds;
uint nT2 = (uint)(tss.Tick s - (nT1 * TimeSpan.TicksP erSecond));
//Ideally nT11 and nT1 should be the same.
//After new Device is created, TimeSpan.TotalS econds does not give
correct value.
if (nT1 != nT11)
{
Debug.WriteLine ("************* *************** *************** *************"
+ "\nPROBLEM! !"
+
"\n************ *************** *************** **************"
+ "\nTicks =" + tss.Ticks.ToStr ing()
+ "\nTotalSeconds (T1) =" + nT1
+ "\nT2 =" + nT2
+ "\nTicks/TicksPerSecond( T11)=" + nT11
+
"\n~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~" );
}
else
{
Debug.WriteLine ("************* *************** *************** *************"
+ "\nEverythi ng OK!!"
+
"\n************ *************** *************** **************"
+ "\nTicks =" + tss.Ticks.ToStr ing()
+ "\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 =11792483786198 544
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 =11792499480265 504
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.
Comment