代码之家  ›  专栏  ›  技术社区  ›  Rex Logan

Winforms我应该多线程还是使用事件计时器?

  •  2
  • Rex Logan  · 技术社区  · 16 年前

    我目前有一个线程,它监听来自网络的数据,然后在上面运行规则。然后,我想将数据传递给GUI。我担心GUI中会出现死锁。我不知道是不是把互斥体放在GUI端。我也在使用c#和.NET 3.5。

    我想到的是

    Threading in Windows Forms Jon Skeet .

      delegate void UInt32ParameterDelegate(UInt32 n);
    
      public void UpdateLocation(UInt32 n)
      {
         if (InvokeRequired)
         {
            // We're not in the UI thread, so we need to call BeginInvoke
            BeginInvoke(new UInt32ParameterDelegate(UpdateLocation), new object[] { n });
            return;
         }
         // Must be on the UI thread if we've got this far
    
         this.engine.location.UpdateBusy.WaitOne();
         // do the work in here
    
         this.engine.location.UpdateBusy.ReleaseMutex();
    
      }
    
    6 回复  |  直到 8 年前
        1
  •  3
  •   Hans Passant    16 年前

        2
  •  3
  •   configurator    16 年前

    我希望我能正确理解你的问题。

    Invoke

        3
  •  2
  •   JaredPar    16 年前

    SynchronizationContext 邮寄或发送方式。

        5
  •  1
  •   Mez    16 年前
        6
  •  0
  •   gbianchi    16 年前