Condividi tramite


[STAThread] and remoting

This is one of the most common gotchas in remoting. VS by default adds a [STAThread] attribue to the Main method of an application. If this attribute is present on a remoting server implementation, and for some reason the main thread is not pumping messages, the finalizer thread will not run which will lead to huge memory leaks. [STAThread] should be avoided in almost all cases for console applications, and if its required the main thread should not block on something like Console.ReadLine.

Comments

  • Anonymous
    August 31, 2004
    According to the docs, this attribute only affects COM interop. I don't see why, then, you'd ever apply it to anything but a class library that's consumed by COM, so naturally, not applying it to console, windows, or (in general) web applications makes perfect sense.
  • Anonymous
    August 31, 2004
    Strike that last comment. Still waking up I guess. :)
  • Anonymous
    June 12, 2009
    PingBack from http://insomniacuresite.info/story.php?id=11126