Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TraceListener.Close not called when added through config file...

TraceListener.Close not called when added through config file...

Scheduled Pinned Locked Moved C#
hostingdebuggingquestion
8 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ryan Cromwell
    wrote on last edited by
    #1

    I have written a trace listener that has at least one worker thread to process an internal buffer. When the Close method is called explicitly from within the hosting application, everthing is fine and dandy, but if i add the TraceListener from the system.diagnostics section of the config file, the Close method doesn't ever get called. Does anyone have any idea when that method gets called when added through the config file?

    J 1 Reply Last reply
    0
    • R Ryan Cromwell

      I have written a trace listener that has at least one worker thread to process an internal buffer. When the Close method is called explicitly from within the hosting application, everthing is fine and dandy, but if i add the TraceListener from the system.diagnostics section of the config file, the Close method doesn't ever get called. Does anyone have any idea when that method gets called when added through the config file?

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      The correct solution is probably to implemente the IDisposable interface on your trace listener. When that object is disposed, you can call the Close method yourself. John
      "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

      R 1 Reply Last reply
      0
      • J John Fisher

        The correct solution is probably to implemente the IDisposable interface on your trace listener. When that object is disposed, you can call the Close method yourself. John
        "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

        R Offline
        R Offline
        Ryan Cromwell
        wrote on last edited by
        #3

        Hmm - turns out a i forgot a vital piece of infornmation. The hosting application hangs when this problem occurs. I implement the Dispose( bool ) method for just this issue, but it never gets to a point where that would be feasible. It appears, at first glance, that the framework is looking for all the threads owned by the hosting app to finish as its trigger for releasing the dynamic config listeners. It becomes a catch-22, it won't call Close until all threads complete, but I can't know to complete my thread without Close being called. :P Ugh - I really don't want to require explicit addition and closure of this tracelistener, even though it would be understandable concidering the purpose and goal of this specific listener implementation.

        J 1 Reply Last reply
        0
        • R Ryan Cromwell

          Hmm - turns out a i forgot a vital piece of infornmation. The hosting application hangs when this problem occurs. I implement the Dispose( bool ) method for just this issue, but it never gets to a point where that would be feasible. It appears, at first glance, that the framework is looking for all the threads owned by the hosting app to finish as its trigger for releasing the dynamic config listeners. It becomes a catch-22, it won't call Close until all threads complete, but I can't know to complete my thread without Close being called. :P Ugh - I really don't want to require explicit addition and closure of this tracelistener, even though it would be understandable concidering the purpose and goal of this specific listener implementation.

          J Offline
          J Offline
          John Fisher
          wrote on last edited by
          #4

          Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
          "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

          R 3 Replies Last reply
          0
          • J John Fisher

            Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
            "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

            R Offline
            R Offline
            Ryan Cromwell
            wrote on last edited by
            #5

            True, i haven't implementing the raw Dispose() yet. I'll give it a try, but i'm not holding out hope. :) Dispose( bool ) is the de-facto method for classes that have finalizers and is implemented by a number of classes, including the TraceListener base class.

            1 Reply Last reply
            0
            • J John Fisher

              Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
              "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

              R Offline
              R Offline
              Ryan Cromwell
              wrote on last edited by
              #6

              yup - can't override the TraceListener.Dispose method. You have to override the Dispose( bool ) method which i've done and had no luck with. Stupid Dispose!

              1 Reply Last reply
              0
              • J John Fisher

                Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
                "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

                R Offline
                R Offline
                Ryan Cromwell
                wrote on last edited by
                #7

                OK - So I figured out a solution, but I have to determine the impact. The worker thread IsBackground property had been set to false, mainly to increase performance. (This is supposed to be part of a high-performance, low impact auditing framework we are writing) I'm going to make the assumption that the Trace framework, waits for all non-background threads to complete before calling close. Thanks for the help...

                J 1 Reply Last reply
                0
                • R Ryan Cromwell

                  OK - So I figured out a solution, but I have to determine the impact. The worker thread IsBackground property had been set to false, mainly to increase performance. (This is supposed to be part of a high-performance, low impact auditing framework we are writing) I'm going to make the assumption that the Trace framework, waits for all non-background threads to complete before calling close. Thanks for the help...

                  J Offline
                  J Offline
                  John Fisher
                  wrote on last edited by
                  #8

                  Glad you found a solution, but I still question the Dispose use. Have you actually put a " : IDisposable" at the end of your class definition? If not, you can do that and then supply at minumum an IDisposable.Dispose() implementation. This will be separate from any dependency upon being able to inherit from TraceListener, but you may need to call the base.Dispose() method to properly clean things up. John
                  "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups