• <bdo id='mdL18'></bdo><ul id='mdL18'></ul>

    <small id='mdL18'></small><noframes id='mdL18'>

    <legend id='mdL18'><style id='mdL18'><dir id='mdL18'><q id='mdL18'></q></dir></style></legend>
    <i id='mdL18'><tr id='mdL18'><dt id='mdL18'><q id='mdL18'><span id='mdL18'><b id='mdL18'><form id='mdL18'><ins id='mdL18'></ins><ul id='mdL18'></ul><sub id='mdL18'></sub></form><legend id='mdL18'></legend><bdo id='mdL18'><pre id='mdL18'><center id='mdL18'></center></pre></bdo></b><th id='mdL18'></th></span></q></dt></tr></i><div id='mdL18'><tfoot id='mdL18'></tfoot><dl id='mdL18'><fieldset id='mdL18'></fieldset></dl></div>

    <tfoot id='mdL18'></tfoot>

        是否有必要同步 .NET SerialPort 写入/读取?

        Is it necessary to synchronize .NET SerialPort writes/reads?(是否有必要同步 .NET SerialPort 写入/读取?)
      1. <tfoot id='tK6ha'></tfoot>
      2. <i id='tK6ha'><tr id='tK6ha'><dt id='tK6ha'><q id='tK6ha'><span id='tK6ha'><b id='tK6ha'><form id='tK6ha'><ins id='tK6ha'></ins><ul id='tK6ha'></ul><sub id='tK6ha'></sub></form><legend id='tK6ha'></legend><bdo id='tK6ha'><pre id='tK6ha'><center id='tK6ha'></center></pre></bdo></b><th id='tK6ha'></th></span></q></dt></tr></i><div id='tK6ha'><tfoot id='tK6ha'></tfoot><dl id='tK6ha'><fieldset id='tK6ha'></fieldset></dl></div>

            <tbody id='tK6ha'></tbody>

              • <bdo id='tK6ha'></bdo><ul id='tK6ha'></ul>

                <legend id='tK6ha'><style id='tK6ha'><dir id='tK6ha'><q id='tK6ha'></q></dir></style></legend>

                <small id='tK6ha'></small><noframes id='tK6ha'>

                  本文介绍了是否有必要同步 .NET SerialPort 写入/读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我使用 .NET SerialPort 类来读取和写入数据.读取是使用 DataReceived 事件完成的,我假设在 ThreadPool 线程内部.编写由 UI 线程(WinForms)完成.

                  In my application I use the .NET SerialPort class for reading and writing data. The reading is done using the DataReceived event, I assume internally on a ThreadPool thread. The writing is done by the UI thread (WinForms).

                  我想知道,是否有必要同步对 SerialPort 实例的访问,以便不会同时发生读/写.我的良心告诉我应该对这些调用加锁,但我很困惑,因为我在 Internet 上找到的所有 C# SerialPort 示例根本不使用锁定.

                  I was wondering, if it's necessary to synchronize the access to the SerialPort instance, so that no Reads/Writes can happen at the same time. My conscience tells me I should put locks around these calls, but I'm puzzled as all C# SerialPort examples I find on the Internet don't use locking at all.

                  推荐答案

                  这里有一个很棒的主题,SerialPort 类的作者参与:

                  Here's a great thread on the topic, with the author of the SerialPort class participating:

                  MSDN:如何SerialPort 是否处理 DataReceived?

                  根据我的经验,我编写了十几个串行通信应用程序用作硬件模拟器,我不锁定.我当时不知道我是否安全,但在实践中,我还没有出错.(20 多位测试人员和自动化测试机器几乎持续使用一年)也就是说,我的应用程序不会离开公司,如果我正在编写供公众使用的应用程序,我可能会更加小心.

                  From my experience, I've written a dozen serial communication apps for use as hardware simulators, I don't lock. I didn't know at the time if I was safe or not, but in practice, I haven't had an error yet. (a year of near constant use by 20+ testers and automated test machines) That said, my applications don't leave the company, if I were writing apps for public consumption I might take more care.

                  这篇关于是否有必要同步 .NET SerialPort 写入/读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='wvE2a'><style id='wvE2a'><dir id='wvE2a'><q id='wvE2a'></q></dir></style></legend>

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

                          <small id='wvE2a'></small><noframes id='wvE2a'>

                            <tbody id='wvE2a'></tbody>

                            <tfoot id='wvE2a'></tfoot>