<tfoot id='DqDf8'></tfoot>

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

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

      1. 在自己的线程中执行的线程之间的 C# 事件(如何)?

        C# Events between threads executed in their own thread (How to)?(在自己的线程中执行的线程之间的 C# 事件(如何)?)
        <legend id='lGigP'><style id='lGigP'><dir id='lGigP'><q id='lGigP'></q></dir></style></legend>

            <bdo id='lGigP'></bdo><ul id='lGigP'></ul>

            <tfoot id='lGigP'></tfoot>

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

                  <tbody id='lGigP'></tbody>

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

                1. 本文介绍了在自己的线程中执行的线程之间的 C# 事件(如何)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想要两个线程.让我们称呼他们:

                  I'd like to have two Threads. Let's call them :

                  • 线程 A
                  • 线程 B

                  线程 A 触发一个事件,线程 B 监听这个事件.当线程B事件监听器执行时,它是用线程A的线程ID执行的,所以我猜它是在线程A内执行的.

                  Thread A fires an event and thread B listen to this event. When the Thread B Event Listener is executed, it's executed with the Thread A's thread ID, so i guess it is executed within the Thread A.

                  我想做的是能够向线程 B 触发事件,说如下:嘿,数据已经为你准备好了,你现在可以处理它了".这个事件必须在它自己的线程中执行,因为它使用了只有他才能访问的东西(比如 UI 控件).

                  What I'd like to do is be able to fire event to Thread B saying something like: "hey, a data is ready for you, you can deal with it now". This event must be executed in its own Thread because it uses things that only him can access (like UI controls).

                  我该怎么做?

                  感谢您的帮助.

                  推荐答案

                  您需要将信息编组回 UI 线程.

                  You'll need to marshal the information back into the UI thread.

                  通常,您将在事件处理程序中处理此问题.例如,假设线程 A 是您的 UI 线程 - 当它订阅线程 B 中对象上的事件时,事件处理程序将在线程 B 内运行.但是,它可以将其封送回 UI 线程:

                  Typically, you would handle this in your Event handler. For example, say Thread A was your UI thread - when it subscribed to an event on an object in Thread B, the event handler will be run inside Thread B. However, it can then just marshal this back into the UI thread:

                  // In Thread A (UI) class...
                  private void myThreadBObject_EventHandler(object sender, EventArgs e)
                  {
                      this.button1.BeginInvoke( new Action(
                          () => 
                              {
                                  // Put your "work" here, and it will happen on the UI thread...
                              }));
                  }
                  

                  这篇关于在自己的线程中执行的线程之间的 C# 事件(如何)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

                    <bdo id='PRbHg'></bdo><ul id='PRbHg'></ul>
                      <tbody id='PRbHg'></tbody>

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

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