DirectX creating problem with TimeSpan structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vibhesh

    DirectX creating problem with TimeSpan structure

    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.

  • Peter Duniho

    #2
    Re: DirectX creating problem with TimeSpan structure

    On Wed, 16 May 2007 09:54:07 -0700, Vibhesh <vibhesh@gmail. comwrote:
    [...]
    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.
    Well, first of all, keep in mind that you are treating the fractional part
    of the number as if it were an actual number. But it's not. It's just
    the numerator of a fraction. The digit count will depend on how large the
    numerator is, and leading zeros that can be seen in the original Ticks
    value will be lost when you treat the numerator as a plain integer and
    print it out that way.

    As for the difference in the seconds portion, I don't really know. You
    didn't offer a concise sample that would allow anyone to reproduce your
    results, so it's not possible to examine the situation you have. I don't
    see any reason that the act of calling any DirectX function would affect
    the calculations you're doing.

    Assuming the code you've posted is indeed the code you're using, it would
    seem impossible to have the results you've claimed. In particular, I see
    no reason that getting the TotalSeconds property from the TimeSpan value
    would produce different results from calculating it based on the Ticks and
    TicksPerSecond properties.

    Note that in your "problemati c" output, the only real problem is that the
    value nT1 is calculated incorrectly. Given its value, the result for nT2
    is correct, and of course the value for nT11 is correct given the Ticks
    value being shown.

    So, if I had to guess, I'd say that you have somehow gotten the wrong
    value for tss.TotalSecond s for some reason. I doubt there's a problem
    with the class itself, so that suggests you've done something wrong in
    your own code. Whether that's using a different TimeSpan value to obtain
    that property than you use elsewhere, or something more subtle like an
    unprotected multi-threaded access to the value, I can't say. You didn't
    post any code that shows what you're actually doing (that is, that is a
    complete-but-concise example that reliably reproduces the problem), so
    there's no way to comment on what you might be doing wrong.

    Pete

    Comment

    • Vibhesh

      #3
      Re: DirectX creating problem with TimeSpan structure

      Here is a sample code that demonstrates the problem.
      To build and run this code you will require DirectX SDK installed on
      your system.

      Follow the steps below to reproduce the problem.
      1.) Create a new Windows Application project in Visual Studio 2003
      (the code will also work in 2005)
      2.) Open the default Form1 in 'Code View'
      3.) Replace the code of Form1 with the code specified below
      4.) Add references to DirectX, Direct3D, and Direct3DX dlls.
      5.) Run the App
      6.) Press TestTimeSpan button to see the output from TimeSpan
      structure and my calculations.
      7.) Press Create Device button to create a new DirectX device object.
      8.) Again press TestTimeSpan button
      HERE YOU WILL SEE THE PROBLEM IN THE TIMESPAN STRUCTURE.
      NOTICE THE DIFFRENCE BETWEEN Ticks and TotalSeconds properties.


      *************** **************C ODE
      (form1.cs)***** *************** ********
      using System;
      using System.Drawing;
      using System.Collecti ons;
      using System.Componen tModel;
      using System.Windows. Forms;
      using System.Data;
      using Microsoft.Direc tX;
      using Microsoft.Direc tX.Direct3D;
      using Direct3D = Microsoft.Direc tX.Direct3D;
      using System.Diagnost ics;

      namespace TestNamespace
      {
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows. Forms.Form
      {
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.Componen tModel.Containe r components = null;
      private System.Windows. Forms.Button btn_TestTimeSpa n;
      private System.Windows. Forms.Button btnCreateDevice ;
      private System.Windows. Forms.Button btnDisposeDevic e;
      private System.Windows. Forms.TextBox txtOutput;
      private Device device = null;

      public Form1()
      {
      //
      // Required for Windows Form Designer support
      //
      InitializeCompo nent();

      }
      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
      if( disposing )
      {
      if (components != null)
      {
      components.Disp ose();
      }
      }
      base.Dispose( disposing );
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeCompo nent()
      {
      this.btn_TestTi meSpan = new System.Windows. Forms.Button();
      this.btnCreateD evice = new System.Windows. Forms.Button();
      this.btnDispose Device = new System.Windows. Forms.Button();
      this.txtOutput = new System.Windows. Forms.TextBox() ;
      this.SuspendLay out();
      //
      // btn_TestTimeSpa n
      //
      this.btn_TestTi meSpan.Location = new System.Drawing. Point(0,
      48);
      this.btn_TestTi meSpan.Name = "btn_TestTimeSp an";
      this.btn_TestTi meSpan.Size = new System.Drawing. Size(104,
      32);
      this.btn_TestTi meSpan.TabIndex = 0;
      this.btn_TestTi meSpan.Text = "Test TimeSpan";
      this.btn_TestTi meSpan.Click += new
      System.EventHan dler(this.btn_T estTimeSpan_Cli ck);
      //
      // btnCreateDevice
      //
      this.btnCreateD evice.Location = new System.Drawing. Point(0,
      8);
      this.btnCreateD evice.Name = "btnCreateDevic e";
      this.btnCreateD evice.Size = new System.Drawing. Size(104, 32);
      this.btnCreateD evice.TabIndex = 1;
      this.btnCreateD evice.Text = "Create Device";
      this.btnCreateD evice.Click += new
      System.EventHan dler(this.btnCr eateDevice_Clic k);
      //
      // btnDisposeDevic e
      //
      this.btnDispose Device.Location = new
      System.Drawing. Point(112, 8);
      this.btnDispose Device.Name = "btnDisposeDevi ce";
      this.btnDispose Device.Size = new System.Drawing. Size(104,
      32);
      this.btnDispose Device.TabIndex = 2;
      this.btnDispose Device.Text = "Dispose Device";
      this.btnDispose Device.Click += new
      System.EventHan dler(this.btnDi sposeDevice_Cli ck);
      //
      // txtOutput
      //
      this.txtOutput. Location = new System.Drawing. Point(8, 96);
      this.txtOutput. Multiline = true;
      this.txtOutput. Name = "txtOutput" ;
      this.txtOutput. ScrollBars =
      System.Windows. Forms.ScrollBar s.Both;
      this.txtOutput. Size = new System.Drawing. Size(656, 408);
      this.txtOutput. TabIndex = 3;
      this.txtOutput. Text = "";
      //
      // Form1
      //
      this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
      this.ClientSize = new System.Drawing. Size(672, 518);
      this.Controls.A dd(this.txtOutp ut);
      this.Controls.A dd(this.btnDisp oseDevice);
      this.Controls.A dd(this.btnCrea teDevice);
      this.Controls.A dd(this.btn_Tes tTimeSpan);
      this.FormBorder Style =
      System.Windows. Forms.FormBorde rStyle.SizableT oolWindow;
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayo ut(false);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
      try
      {
      using (Form1 frm = new Form1())
      {
      frm.Show();
      Application.Run (frm);
      }
      }
      catch (Exception e)
      {
      System.Windows. Forms.MessageBo x.Show("Problem in
      application, will now exit. " + e.Message);
      }
      }

      private void CreateDevice()
      {
      PresentParamete rs presentParams = new PresentParamete rs();
      presentParams.W indowed = true;
      presentParams.S wapEffect = SwapEffect.Disc ard;
      presentParams.A utoDepthStencil Format = DepthFormat.D16 ;
      presentParams.E nableAutoDepthS tencil = true;

      device = new Device(0, DeviceType.Hard ware, this,
      CreateFlags.Sof twareVertexProc essing, presentParams);
      }
      private void DisposeDevice()
      {
      device.Dispose( );
      }
      public void TimeSpanProblem (string strFrom)
      {
      DateTime dt1970 = new DateTime(1970, 1, 1);
      //LoadVC();
      System.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));
      string displayStr = "@@@@@@@@@"+str From+"@@@@@@@@@ ";
      if (nT1 != nT11)
      {
      displayStr += Environment.New Line +
      "************** *************** *************** ************"
      + Environment.New Line + "PROBLEM!! T1 != T11 (NOTICE
      THAT THE DECIMALS ARE GONE FOR TotalSeconds)"
      + Environment.New Line +
      "************** *************** *************** ************";
      }
      else
      {
      displayStr += Environment.New Line +
      "************** *************** *************** ************"
      + Environment.New Line + "Everything OK!!"
      + Environment.New Line +
      "************** *************** *************** ************";
      }

      displayStr+=
      Environment.New Line + "------TimeSpan---------"
      + Environment.New Line + "tss.Ticks
      =
      {0}"
      + Environment.New Line + "tss.TotalSecon ds
      =
      {1}"
      + Environment.New Line + "------My Variables---------"
      + Environment.New Line + "T1 = (uint)tss.Total Seconds
      = {2}"
      + Environment.New Line + "T2 = (uint)(tss.Tick s - (nT1
      * TimeSpan.TicksP erSecond)) = {3}"
      + Environment.New Line + "T11 = (uint)(tss.Tick s /
      TimeSpan.TicksP erSecond) = {4}"
      + Environment.New Line +
      "~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~"+E nvironment.NewL ine
      +Environment.Ne wLine+Environme nt.NewLine;

      txtOutput.Text +=
      String.Format(d isplayStr,tss.T icks,tss.TotalS econds,nT1,nT2, nT11);
      txtOutput.Selec t(txtOutput.Tex t.Length-2,1);
      txtOutput.Scrol lToCaret();
      }

      private void btn_TestTimeSpa n_Click(object sender,
      System.EventArg s e)
      {
      this.TimeSpanPr oblem("From btn_TestTimeSpa n_Click");
      }

      private void btnCreateDevice _Click(object sender,
      System.EventArg s e)
      {
      CreateDevice();
      }

      private void btnDisposeDevic e_Click(object sender,
      System.EventArg s e)
      {
      DisposeDevice() ;
      }

      }
      }

      *************** **************C ODE
      END************ *************** *******


      Comment

      • Vibhesh

        #4
        Re: DirectX creating problem with TimeSpan structure


        Vibhesh wrote:
        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.

        Comment

        • Peter Duniho

          #5
          Re: DirectX creating problem with TimeSpan structure

          On Thu, 17 May 2007 09:49:22 -0700, Vibhesh <vibhesh@gmail. comwrote:
          Here is a sample code that demonstrates the problem.
          To build and run this code you will require DirectX SDK installed on
          your system. [...]
          Huh. Well, I can confirm your problem. The exact same results occur on
          my computer with your code.

          But I have no good answer. Please note that you will probably have to
          report this to Microsoft customer support (use the online form, there
          should be no charge since it seems clear it's a bug in their own
          software), and you may get a suitable resolution from them.

          You might be able to learn more by stepping into the TotalSeconds property
          getter (I haven't tried this, but it seems to me that if you are viewing
          disassembly while you are debugging, you should be able to step into the
          code) and seeing what it's doing. I would think it would just do the same
          "divide by TicksPerSecond" that you do in your own example code, but
          obviously it's not as simple as that.

          In the meantime, since doing the conversion yourself directly is easy and
          does work, it seems to me that's a perfectly suitable workaround.

          Pete

          Comment

          • Willy Denoyette [MVP]

            #6
            Re: DirectX creating problem with TimeSpan structure

            "Vibhesh" <vibhesh@gmail. comwrote in message
            news:1179420562 .665157.171750@ o5g2000hsb.goog legroups.com...
            Here is a sample code that demonstrates the problem.
            To build and run this code you will require DirectX SDK installed on
            your system.
            >
            Follow the steps below to reproduce the problem.
            1.) Create a new Windows Application project in Visual Studio 2003
            (the code will also work in 2005)
            2.) Open the default Form1 in 'Code View'
            3.) Replace the code of Form1 with the code specified below
            4.) Add references to DirectX, Direct3D, and Direct3DX dlls.
            5.) Run the App
            6.) Press TestTimeSpan button to see the output from TimeSpan
            structure and my calculations.
            7.) Press Create Device button to create a new DirectX device object.
            8.) Again press TestTimeSpan button
            HERE YOU WILL SEE THE PROBLEM IN THE TIMESPAN STRUCTURE.
            NOTICE THE DIFFRENCE BETWEEN Ticks and TotalSeconds properties.
            >
            >
            *************** **************C ODE
            (form1.cs)***** *************** ********
            using System;
            using System.Drawing;
            using System.Collecti ons;
            using System.Componen tModel;
            using System.Windows. Forms;
            using System.Data;
            using Microsoft.Direc tX;
            using Microsoft.Direc tX.Direct3D;
            using Direct3D = Microsoft.Direc tX.Direct3D;
            using System.Diagnost ics;
            >
            namespace TestNamespace
            {
            /// <summary>
            /// Summary description for Form1.
            /// </summary>
            public class Form1 : System.Windows. Forms.Form
            {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.Componen tModel.Containe r components = null;
            private System.Windows. Forms.Button btn_TestTimeSpa n;
            private System.Windows. Forms.Button btnCreateDevice ;
            private System.Windows. Forms.Button btnDisposeDevic e;
            private System.Windows. Forms.TextBox txtOutput;
            private Device device = null;
            >
            public Form1()
            {
            //
            // Required for Windows Form Designer support
            //
            InitializeCompo nent();
            >
            }
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
            if( disposing )
            {
            if (components != null)
            {
            components.Disp ose();
            }
            }
            base.Dispose( disposing );
            }
            >
            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeCompo nent()
            {
            this.btn_TestTi meSpan = new System.Windows. Forms.Button();
            this.btnCreateD evice = new System.Windows. Forms.Button();
            this.btnDispose Device = new System.Windows. Forms.Button();
            this.txtOutput = new System.Windows. Forms.TextBox() ;
            this.SuspendLay out();
            //
            // btn_TestTimeSpa n
            //
            this.btn_TestTi meSpan.Location = new System.Drawing. Point(0,
            48);
            this.btn_TestTi meSpan.Name = "btn_TestTimeSp an";
            this.btn_TestTi meSpan.Size = new System.Drawing. Size(104,
            32);
            this.btn_TestTi meSpan.TabIndex = 0;
            this.btn_TestTi meSpan.Text = "Test TimeSpan";
            this.btn_TestTi meSpan.Click += new
            System.EventHan dler(this.btn_T estTimeSpan_Cli ck);
            //
            // btnCreateDevice
            //
            this.btnCreateD evice.Location = new System.Drawing. Point(0,
            8);
            this.btnCreateD evice.Name = "btnCreateDevic e";
            this.btnCreateD evice.Size = new System.Drawing. Size(104, 32);
            this.btnCreateD evice.TabIndex = 1;
            this.btnCreateD evice.Text = "Create Device";
            this.btnCreateD evice.Click += new
            System.EventHan dler(this.btnCr eateDevice_Clic k);
            //
            // btnDisposeDevic e
            //
            this.btnDispose Device.Location = new
            System.Drawing. Point(112, 8);
            this.btnDispose Device.Name = "btnDisposeDevi ce";
            this.btnDispose Device.Size = new System.Drawing. Size(104,
            32);
            this.btnDispose Device.TabIndex = 2;
            this.btnDispose Device.Text = "Dispose Device";
            this.btnDispose Device.Click += new
            System.EventHan dler(this.btnDi sposeDevice_Cli ck);
            //
            // txtOutput
            //
            this.txtOutput. Location = new System.Drawing. Point(8, 96);
            this.txtOutput. Multiline = true;
            this.txtOutput. Name = "txtOutput" ;
            this.txtOutput. ScrollBars =
            System.Windows. Forms.ScrollBar s.Both;
            this.txtOutput. Size = new System.Drawing. Size(656, 408);
            this.txtOutput. TabIndex = 3;
            this.txtOutput. Text = "";
            //
            // Form1
            //
            this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
            this.ClientSize = new System.Drawing. Size(672, 518);
            this.Controls.A dd(this.txtOutp ut);
            this.Controls.A dd(this.btnDisp oseDevice);
            this.Controls.A dd(this.btnCrea teDevice);
            this.Controls.A dd(this.btn_Tes tTimeSpan);
            this.FormBorder Style =
            System.Windows. Forms.FormBorde rStyle.SizableT oolWindow;
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayo ut(false);
            >
            }
            #endregion
            >
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
            try
            {
            using (Form1 frm = new Form1())
            {
            frm.Show();
            Application.Run (frm);
            }
            }
            catch (Exception e)
            {
            System.Windows. Forms.MessageBo x.Show("Problem in
            application, will now exit. " + e.Message);
            }
            }
            >
            private void CreateDevice()
            {
            PresentParamete rs presentParams = new PresentParamete rs();
            presentParams.W indowed = true;
            presentParams.S wapEffect = SwapEffect.Disc ard;
            presentParams.A utoDepthStencil Format = DepthFormat.D16 ;
            presentParams.E nableAutoDepthS tencil = true;
            >
            device = new Device(0, DeviceType.Hard ware, this,
            CreateFlags.Sof twareVertexProc essing, presentParams);
            }
            private void DisposeDevice()
            {
            device.Dispose( );
            }
            public void TimeSpanProblem (string strFrom)
            {
            DateTime dt1970 = new DateTime(1970, 1, 1);
            //LoadVC();
            System.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));
            string displayStr = "@@@@@@@@@"+str From+"@@@@@@@@@ ";
            if (nT1 != nT11)
            {
            displayStr += Environment.New Line +
            "************** *************** *************** ************"
            + Environment.New Line + "PROBLEM!! T1 != T11 (NOTICE
            THAT THE DECIMALS ARE GONE FOR TotalSeconds)"
            + Environment.New Line +
            "************** *************** *************** ************";
            }
            else
            {
            displayStr += Environment.New Line +
            "************** *************** *************** ************"
            + Environment.New Line + "Everything OK!!"
            + Environment.New Line +
            "************** *************** *************** ************";
            }
            >
            displayStr+=
            Environment.New Line + "------TimeSpan---------"
            + Environment.New Line + "tss.Ticks
            =
            {0}"
            + Environment.New Line + "tss.TotalSecon ds
            =
            {1}"
            + Environment.New Line + "------My Variables---------"
            + Environment.New Line + "T1 = (uint)tss.Total Seconds
            = {2}"
            + Environment.New Line + "T2 = (uint)(tss.Tick s - (nT1
            * TimeSpan.TicksP erSecond)) = {3}"
            + Environment.New Line + "T11 = (uint)(tss.Tick s /
            TimeSpan.TicksP erSecond) = {4}"
            + Environment.New Line +
            "~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~"+E nvironment.NewL ine
            +Environment.Ne wLine+Environme nt.NewLine;
            >
            txtOutput.Text +=
            String.Format(d isplayStr,tss.T icks,tss.TotalS econds,nT1,nT2, nT11);
            txtOutput.Selec t(txtOutput.Tex t.Length-2,1);
            txtOutput.Scrol lToCaret();
            }
            >
            private void btn_TestTimeSpa n_Click(object sender,
            System.EventArg s e)
            {
            this.TimeSpanPr oblem("From btn_TestTimeSpa n_Click");
            }
            >
            private void btnCreateDevice _Click(object sender,
            System.EventArg s e)
            {
            CreateDevice();
            }
            >
            private void btnDisposeDevic e_Click(object sender,
            System.EventArg s e)
            {
            DisposeDevice() ;
            }
            >
            }
            }
            >
            *************** **************C ODE
            END************ *************** *******
            >
            >


            I can confirm the issue. The problem is with DirectX resetting the X87
            control word, more precisely, the CLR initially sets the FPU to double
            precision mode (FCW = 27Fh), however, when DX initializes, it switches the
            FPU to single precision mode by resetting the FCW to 7Fh.
            The result is that TotalSeconds returns a wrong value, as this routine
            expects the FPU to be in double precision mode. The point is who to blame?
            DX or the CLR? I would suggest you to do as Peter said, file a bug. In the
            mean time I would stay away from the TimeSpan class and use the StopWatch
            class.

            Willy.




            Willy.

            Comment

            Working...