Trace.WriteLine 线程安全吗? [英] Is Trace.WriteLine thread safe?

查看:37
本文介绍了Trace.WriteLine 线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程程序,我想对其使用 Trace.WriteLine,并将输出重定向到一个文本文件:

I have a multithreaded program for which I'd like to use the Trace.WriteLine, and redirect the output to a text file:

_LogTracer = new System.Diagnostics.TextWriterTraceListener(logPath);   
Trace.AutoFlush = true;
Trace.Listeners.Add(_LogTracer); 

这足以保证线程安全吗?如果两个线程同时尝试写入输出文件怎么办?

Is this sufficient to be thread safe? What if two threads are trying to write to the output file at the same time?

推荐答案

来自 Microsoft 文档:

这种类型是线程安全的.

Thread Safety

This type is thread safe.

这篇关于Trace.WriteLine 线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆