I think this one is silly question, but it was a bit strange for me to discover that i cant do the following:
EditingItem.FROM = EditingItem.TO = DateTime.Now; // FROM, TO are DateTime
after this manipulations, the program sometimes hangs, but sometimes it just works as i thought it should.
Here is the exception:
ContextSwitchDeadlock was detected Message: The CLR has been unable to
transition from COM context 0x478b80 to COM context 0x478dd0 for 60
seconds. The thread that owns the destination context/apartment is
most likely either doing a non pumping wait or processing a very long
running operation without pumping Windows messages. This situation
generally has a negative performance impact and may even lead to the
application becoming non responsive or memory usage accumulating
continually over time. To avoid this problem, all single threaded
apartment (STA) threads should use pumping wait primitives (such as
CoWaitForMultipleHandles) and routinely pump messages during long
running operations.
Changing the code to:
EditingItem.FROM = DateTime.Now;
EditingItem.TO = DateTime.Now;
helps in my situation.
Cant google the question properly, to see explanation, so can you help and explain why whis expression is wrong?
PS more discussion in comments.
Here are some results from experiments:
DateTime d = DateTime.Now;
EditingItem.FROM = EditingItem.TO = d;//hang
added loop for timing:
for (int i = 0; i < 100000; i++)
{
i++;
}
DateTime d = DateTime.Now;
EditingItem.FROM = EditingItem.TO = d;//hang
Your problem is that there seems to be a
lockhappening – again code not provided so just a guess – where object is locked so that assigning a property from another property will deadlock on itself.If you are dealing with COM, this can be maginfied by the fact that COM objects are Single-Threaded Apartment objects.