c# - Threads locked in TraceSource methods by Console -


i've run situation , don't know if can resolved.

i've started adding tracesource , trace statements multithreaded service, , i'm running locks in threads process trace methods in code. causing entire app hang.

my service configured run within console window debugging purposes. know related issue writing consoletracelistener.

this locking seems occur between external code , internal call console.readkey(). example of code , configuration, application may make calls such these within async methods:

class myservice : servicebase {     static tracesource trace = new tracesource("mysource");      void asyncmethod1()     {         trace.traceinformation("some useful information.");     }      void asyncmethod2()     {         trace.traceinformation("some other useful information.");     }      /// other members , methods ... } 

the tracesource defined in app.config file as

<?xml version="1.0" encoding="utf-8"?> <configuration>   <startup>     <supportedruntime version="v4.0" sku=".netframework,version=v4.0"/>   </startup>   <system.diagnostics>     <trace autoflush="true" indentsize="4" usegloballock="true" />     <sources>       <source name="mysource" switchname="traceswitch" switchtype="system.diagnostics.sourceswitch">         <listeners>           <add name="console" />           <add name="eventlog" />           <add name="logfile" />         </listeners>       </source>     </sources>     <sharedlisteners>       <add name="console" type="system.diagnostics.consoletracelistener" initializedata="false" />       <add name="eventlog" type="system.diagnostics.eventlogtracelistener" initializedata="eventsource">         <filter type="system.diagnostics.eventtypefilter" initializedata="error"/>       </add>       <add name="logfile" type="system.diagnostics.textwritertracelistener" initializedata="logfiles\errors.log">         <filter type="system.diagnostics.eventtypefilter" initializedata="error"/>       </add>     </sharedlisteners>     <switches>       <add name="traceswitch" value="information" />     </switches>   </system.diagnostics> </configuration> 

reproducing issue

once app started, code in program.main(args[]) waits console.readkey() stop app.

static int main(string[] args) {     /// ...      myservice service = new myservice();     service.startservice();      console.writeline("press key exit application.");     console.readkey(true);      ///... } 

when run service in console, , using quickedit mode click or select mouse anywhere in console window, tracesource method calls lock rest of application, until hit key stops application.

is there way can prevent console thread locking other threads? or misinterpret happening here?


after click in console window reproduce issue, call stack may this:

thread 1

[managed native transition]   system.io.__consolestream.writefilenative system.io.__consolestream.write system.io.streamwriter.flush system.io.streamwriter.write system.io.textwriter.synctextwriter.write system.diagnostics.textwritertracelistener.write system.diagnostics.tracelistener.writeheader system.diagnostics.tracelistener.traceevent system.diagnostics.tracesource.traceevent system.diagnostics.tracesource.traceinformation myservice.myservice.asyncmethod1 line 202   c# 

thread 2

system.threading.monitor.enter system.diagnostics.tracesource.traceevent system.diagnostics.tracesource.traceinformation myservice.myservice.asyncmethod2 line 134   c# 

op:

when run service in console, , click mouse anywhere in console window, tracesource method calls lock rest of application, until hit key stops application.

would try turning on quickedit in console, , use mouse highlight characters?

based on our conversation below question above, reason appears hang during quickedit mode/highlighting text, console output suspended threads. confirmed in visual studio debugger.

to resume execution, press esc or click right mouse button.

op:

i wondering know if there way prevent behaviour

yes, jim mishel writes:

if want disable quick edit mode, need call getconsolemode current mode. clear bit enables quick edit

you can find more jim's answer here.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -