Attention: We are retiring the ASP.NET Community Blogs. Learn more >

.NET Remoting and Multiple Threads...beware

I have spent 5 days debugging our application, which uses .net remoting, only to discover the issue was with multiple threads.

We have a WinForms application that runs on the LAN or WAN.  The app is depolyed over from a web server (No Touch Deploy).

The remote server, hosted by IIS, is for data access: searches and update.

We use a shared implementation when it comes to remoting.  The client assemblies are compiled against the data access asembly.  So, the data access assembly lives with the client and it also lives on the web server.  Whe a user is running the app on the LAN, we use TCP\binary and the data access asembly the client was build with.

When the user is on the WAN, we use HTTP\soap and the data access assembly hosted by IIS.  Same exact assembly.

At runtime we have some client decision logic that decides which assembly to use.

When running the app from the WAN, all of our searches work fine with the remote assembly.  Our search logic uses multiple threads (running in the background) to pull back lookup data when the app first starts.  So, multiple threads where making calls to the remote server.

Now, once the app loaded up and we tried to do an update, we'd get remoting exceptions. I could do another search just fine.  If I tried to do an update though, more remoting exceptions.

After debugging my ^%$# off, I finally noticed that the background threads for our searches were the problem.  Once I 'truend these off' and did all the search work on the main thread, updates worked remotely.

Now, I cannot explan why.  Our client has a shared type that all assemblies call into when the need to do a lookup or an update.  The shared type is responsible for creating a data access object, using the local copy or the remote copy.

The shared type than calls into the data access assembly.  For searches this worked fine.  After doing a search (which used many threads) and then an update (which uses the main thread) the shared type could not see the remote server.

Who knows.  Its working when doing everything on the main thread.  I will figure out why it was broken later.  

  

No Comments