This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I've looked around this forum for an answer to this but can't quite find what I'm looking for. Here's a basic test case, stripped down to its essentials:
And here's the calling code:
What happens here is that the new thread blocks the main thread from executing. The while loop is never entered. As far as I can understand from other posts on the subject, this should work. Am I missing something? Edit: I should perhaps also note that the call to the database takes a lot of time, around 20 seconds, so it's not just that the call is finished before the while loop has a chance to be entered. Regards, Faner |
|
|
Yes, it should work. I gave it a quick try and it worked for me. In fact at first I saw the opposite symptom: the tight loop in the while loop starved the background database query thread. When I added a Thread.Sleep the worker thread was able to run to completion:
Output:
Try adding some logging and a Thread.Sleep to see if you can figure out what is blocking and where. You might also want to switch over to an AutoResetEvent or other synchronisation object to avoid the busy-wait and see if that helps. Failing that, if you can provide us with a buildable project (console or class library containing NUnit test) that exhibits the error then we can try it here. |
|
|
Ok thanks, At least I know I'm not just missing something obvious. In my real implementation, there is no busy-wait or sleep problem, as the main thread and other worker threads all have other things to do, including appropriate waits. It's just that they all stop doing anything as soon as I reach the database lookup. What's more, Visual Studio also stops responding to input. It takes input (the gui works), but as soon as I ask it to stop debugging for example, it stops responding completely until the database lookup is done. A hung up thread shouldn't cause this. I'm beginning to think there's something else amiss here, perhaps not related to Lightspeed at all. If I run the test case, wait all that time and then run it again, sometimes (not very often) it all just falls through in a heart beat. I suspect there's something about the initial database lookup/connection that's taking so long. I will also attempt to run it without debugging later on tonight to see what happens. Don't know if it helps, but my setup is an SQL Server 2008 R2 Express database, on the local machine (8 core, 9 gigs of ram, Windows 7), Visual Studio 2010, .Net 4.0, Lightspeed Nightly from 2012-04-30 and the connection string pointing out the database using the workstation's network name (not localhost or ip address). If my further investigation is unsuccessful in finding anything, I will put a test case together for you. Thanks! Faner |
|
|
Ok, I did a bit more of testing. What I found is that it's probably not the lookup itself, as it all works fine if the connection string is incorrect, causing an exception later on. I've also created a test project which gave me the following output. I included some of the dll loading in case it tells you anything.
However, I did one thing to the test project that seems to work every time, following your example which is to change the line
into
There seems to be something going on with the immediate use of LINQ there. Thoughts? Does the test project work in the same way for you? Regards Faner |
|
|
Your test project runs fine for me. The database thread is entered, LightSpeed kicks off the LINQ query on the database thread, the foreground thread keeps printing, and when the LINQ query returns, the database thread exits and then the foreground thread drops out of the print loop.
You observe that sometimes it falls through very quickly which makes it sound like some sort of database locking issue. But if changing from LINQ to Find reliably yields then that couldn't be down to the database. You could try adding extra logging to capture timestamps within the thread method -- when does the thread start running? -- and turning on LightSpeed SQL logging, to try to pin down where the hold-up is occurring. I also note that your DLL loads seem to be happening after the 27-second delay whereas mine are happening at the beginning of the 6-second delay. What happens if you force the LINQ DLL to load before entering the thread, e.g. by performing a dummy operation? |
|
|
Ok, I did as you asked (please find the example project once again attached), here's the result:
So, it seems, it happens only when the LINQ dll is loaded. Loading the assembly is what seems to be taking time. You can clearly see that the second lookup was pretty much instant. The same is true if I force the assembly to be loaded earlier, no problem at the lookup then. Just to be clear, using Find< T > solves my problem, it works just as well. I would just very much like to know what the problem is, and maybe you do too. Thanks Faner |
|
|
...oh and in case I didn't say earlier, running it without debugging is fine too. Sounds more like a Visual Studio problem than a problem with LightSpeed, it's just so wierd that it would have a problem with loading symbols from the LightSpeed LINQ assembly. Faner |
|
|
Wow, that's really weird. I can't imagine what would cause just that one DLL to load slowly under the debugger. My first thought was that maybe you had a symbol server configured but that symbol server was slow or didn't exist, but I'd expect that to affect the base LightSpeed DLL too. Also, I assume this doesn't happen if you load the LINQ DLL on the main thread, or you'd have noticed it earlier. Is that right? (If so, it could give you a workaround that doesn't force you to fall back to query objects -- get the DLL to load on the foreground thread so it's all ready by the time the background thread needs it.) Anyway, glad to hear you have an acceptable workaround and we'll keep our eyes open to understand what might have been going on here. Thanks for all the info! |
|
|
Actually, which thread first caused the DLL load didn't matter. Only reason I hadn't noticed earlier was simply because I hadn't used LINQ lookups directly before. I'll get back to you in case I run into any more useful info. Thank you for you quick responses! Faner |
|