Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That's definitely a weird case. A couple of things can alter the result of the parse. </p> <ol> <li>CultureInfo: by default Parse uses CurrentCulture. If you have something funny on your globalization settings that triggers the change of your current culture, that could be affected.</li> <li>Per MSDN: 'The Parse method attempts to parse a string with several implicit parse patterns' and if you throw culture patterns in it, you can end up with quite a mess.</li> </ol> <p>My suggestions to try:</p> <ol> <li>Use the ParseExact method instead of Parse and enforce a format on your date time string.</li> <li>Use InvariantCulture when parsing your date time (if your application date time format is universal, which I assume it is since you are storing ticks) </li> </ol> <p>On your setter try this:</p> <pre><code>if (string.IsNullOrEmpty(value)) { this.Ticks = 0; } else { CultureInfo provider = CultureInfo.InvariantCulture; var dateTime = DateTime.ParseExact(value, "yyyy-MM-dd hh:mm:ss", provider); this.Ticks = dateTime.ToUniversalTime().Ticks; } </code></pre> <p>Good luck!</p> <p><strong>Edit 1</strong><br> Something else came to my mind: ThreadSafety. If you are accessing the reflected object of Ticks (in your setter you do this.Ticks) from multiple threads you should make it an atomic operation.</p> <pre><code>//same setter code except last line... var oldTicks = this.Ticks; var newTicks = dateTime.ToUniversalTime().Ticks; while(oldTicks != Interlocked.Exchange(ref this.Ticks, newTicks)) { //your break code here } </code></pre> <p>Sorta :)<br> Let me know if any of this helped to solve the mystery.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload