<i id='dcPZ6'><tr id='dcPZ6'><dt id='dcPZ6'><q id='dcPZ6'><span id='dcPZ6'><b id='dcPZ6'><form id='dcPZ6'><ins id='dcPZ6'></ins><ul id='dcPZ6'></ul><sub id='dcPZ6'></sub></form><legend id='dcPZ6'></legend><bdo id='dcPZ6'><pre id='dcPZ6'><center id='dcPZ6'></center></pre></bdo></b><th id='dcPZ6'></th></span></q></dt></tr></i><div id='dcPZ6'><tfoot id='dcPZ6'></tfoot><dl id='dcPZ6'><fieldset id='dcPZ6'></fieldset></dl></div>
      • <bdo id='dcPZ6'></bdo><ul id='dcPZ6'></ul>
    1. <small id='dcPZ6'></small><noframes id='dcPZ6'>

        <tfoot id='dcPZ6'></tfoot>
        <legend id='dcPZ6'><style id='dcPZ6'><dir id='dcPZ6'><q id='dcPZ6'></q></dir></style></legend>

        通过不同的线程同时读取和写入串行端口是否安全?

        Is it safe to read and write to a serial port at the same time via different threads?(通过不同的线程同时读取和写入串行端口是否安全?)

      1. <small id='GEMrr'></small><noframes id='GEMrr'>

      2. <legend id='GEMrr'><style id='GEMrr'><dir id='GEMrr'><q id='GEMrr'></q></dir></style></legend>
          <tbody id='GEMrr'></tbody>

        <tfoot id='GEMrr'></tfoot>
        • <bdo id='GEMrr'></bdo><ul id='GEMrr'></ul>

                <i id='GEMrr'><tr id='GEMrr'><dt id='GEMrr'><q id='GEMrr'><span id='GEMrr'><b id='GEMrr'><form id='GEMrr'><ins id='GEMrr'></ins><ul id='GEMrr'></ul><sub id='GEMrr'></sub></form><legend id='GEMrr'></legend><bdo id='GEMrr'><pre id='GEMrr'><center id='GEMrr'></center></pre></bdo></b><th id='GEMrr'></th></span></q></dt></tr></i><div id='GEMrr'><tfoot id='GEMrr'></tfoot><dl id='GEMrr'><fieldset id='GEMrr'></fieldset></dl></div>
                  本文介绍了通过不同的线程同时读取和写入串行端口是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  通过不同的线程(一个读线程和一个写线程)同时读写一个串口是否安全?是否有必要在每个线程中添加围绕读/写的锁定?

                  Is it safe to read and write to a serial port at the same time via different threads (one read thread and one write thread)? Would it be necessary to add locking around reading/writing in each thread?

                  推荐答案

                  来自 串口:

                  此类型的任何公共静态(在 Visual Basic 中为共享)成员都是线程安全的.不保证任何实例成员都是线程安全的.

                  Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

                  由于读取和写入不是静态的,它们不会是线程安全的.无论如何,这是一个非常糟糕的主意,因为 SerialPort 类为您维护内部缓冲区.

                  Since Read and Write are not static, they would not be threadsafe. It's a very bad idea, in any case, since the SerialPort class maintains internal buffers for you.

                  您需要将 I/O 与串行端口同步.

                  You'll need to synchronize your I/O to your serial port.

                  这篇关于通过不同的线程同时读取和写入串行端口是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                • <legend id='tQDaU'><style id='tQDaU'><dir id='tQDaU'><q id='tQDaU'></q></dir></style></legend>
                • <i id='tQDaU'><tr id='tQDaU'><dt id='tQDaU'><q id='tQDaU'><span id='tQDaU'><b id='tQDaU'><form id='tQDaU'><ins id='tQDaU'></ins><ul id='tQDaU'></ul><sub id='tQDaU'></sub></form><legend id='tQDaU'></legend><bdo id='tQDaU'><pre id='tQDaU'><center id='tQDaU'></center></pre></bdo></b><th id='tQDaU'></th></span></q></dt></tr></i><div id='tQDaU'><tfoot id='tQDaU'></tfoot><dl id='tQDaU'><fieldset id='tQDaU'></fieldset></dl></div>
                        <bdo id='tQDaU'></bdo><ul id='tQDaU'></ul>
                      • <small id='tQDaU'></small><noframes id='tQDaU'>

                          <tbody id='tQDaU'></tbody>
                        • <tfoot id='tQDaU'></tfoot>