Search Results

Search found 2 results on 1 pages for 'groxx'.

Page 1/1 | 1 

  • IPreInsertEventListener makes object dirty, causes invalid update

    - by Groxx
    In NHibernate 2.1.2: I'm attempting to set a created timestamp on insert, as demonstrated here. I have this: public bool OnPreInsert(PreInsertEvent @event) { if (@event.Entity is IHaveCreatedTimestamp) { DateTime dt = DateTime.Now; string Created = ((IHaveCreatedTimestamp)@event.Entity).CreatedPropertyName; SetState(@event.Persister, @event.State, Created, dt); @event.Entity.GetType().GetProperty(Created).SetValue(@event.Entity, dt, null); } // return true to veto the insert return false; } The problem is that doing this (or duplicating Ayende's example precisely, or reordering or removing lines) causes an update after the insert. The insert uses the correct "now" value, @p6 = 3/8/2011 5:41:22 PM, but the update tries to set the Created column to @p6 = 1/1/0001 12:00:00 AM, which is outside MSSQL's range: Test 'CanInsertAndDeleteInserted' failed: System.Data.SqlTypes.SqlTypeException : SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. I've tried the same thing with the PerformSaveOrUpdate listener, described here, but that also causes an update and an insert, and elsewhere there have been mentions of avoiding it because it is called regardless of if the object is dirty or not :/ Searching around elsewhere, there are plenty of claims of success after setting both the state and the object to the same value, or by using the save listener, or of the cause coming from collections or other objects, but I'm not having any success.

    Read the article

  • .NET threading: how can I capture an abort on an unstarted thread?

    - by Groxx
    I have a chunk of threads I wish to run in order, on an ASP site running .NET 2.0 with Visual Studio 2008 (no idea how much all that matters, but there it is), and they may have aborted-clean-up code which should be run regardless of how far through their task they are. So I make a thread like this: Thread t = new Thread(delegate() { try { /* do things */ System.Diagnostics.Debug.WriteLine("try"); } catch (ThreadAbortException) { /* cleanup */ System.Diagnostics.Debug.WriteLine("catch"); } }); Now, if I wish to abort the set of threads part way through, the cleanup may still be desirable later on down the line. Looking through MSDN implies you can .Abort() a thread that has not started, and then .Start() it, at which point it will receive the exception and perform normally. Or you can .Join() the aborted thread to wait for it to finish aborting. Presumably you can combine them. http://msdn.microsoft.com/en-us/library/ty8d3wta(v=VS.80).aspx To wait until a thread has aborted, you can call the Join method on the thread after calling the Abort method, but there is no guarantee the wait will end. If Abort is called on a thread that has not been started, the thread will abort when Start is called. If Abort is called on a thread that is blocked or is sleeping, the thread is interrupted and then aborted. Now, when I debug and step through this code: t.Abort(); // ThreadState == Unstarted | AbortRequested t.Start(); // throws ThreadStartException: "Thread failed to start." // so I comment it out, and t.Join(); // throws ThreadStateException: "Thread has not been started." At no point do I see any output, nor do any breakpoints on either the try or catch block get reached. Oddly, ThreadStartException is not listed as a possible throw of .Start(), from here: http://msdn.microsoft.com/en-us/library/a9fyxz7d(v=VS.80).aspx (or any other version) I understand this could be avoided by having a start parameter, which states if the thread should jump to cleanup code, and foregoing the Abort call (which is probably what I'll do). And I could .Start() the thread, and then .Abort() it. But as an indeterminate amount of time may pass between .Start and .Abort, I'm considering it unreliable, and the documentation seems to say my original method should work. Am I missing something? Is the documentation wrong? edit: ow. And you can't call .Start(param) on a non-parameterized Thread(Start). Is there a way to find out if a thread is parameterized or not, aside from trial and error? I see a private m_Delegate, but nothing public...

    Read the article

1