简体   繁体   English

将事件数据发送到其他表单时响应时间慢

[英]Slow Response Time when sending event data to another form

I have a C# winform application that has 4 distinct user controls on the screen. 我有一个C#winform应用程序,该应用程序在屏幕上具有4个不同的用户控件。 Each of these user controls contains a datagridview control. 这些用户控件均包含一个datagridview控件。 When the user updates a cell value in any one of these 4 control I raise a custom event sending the value of the cell to a 5th form on the screen. 当用户在这4个控件中的任何一个中更新单元格值时,我都会引发一个自定义事件,将单元格的值发送到屏幕上的第5个窗体。

This 5th form is very similar to an Excel spreadsheet. 第5种形式与Excel电子表格非常相似。 The 5th form must show the new value sent on it's pane/window. 第5个表单必须显示在其窗格/窗口上发送的新值。 The issue is not in sending the data from any of the 4 user controls, that works and is reflected on the 5th form. 问题不在于从4个用户控件中的任何一个发送数据,它起作用并且反映在第5个表单上。

However, when the event to send data is raised it stops the user input for a few seconds. 但是,当发送数据的事件发生时,它将停止用户输入几秒钟。 I think the 5th form is busy updating the cells. 我认为5号表格正在忙于更新单元格。 So my question is if I implement a message queue or something similar (wcf) for sending the new values to the spreadsheet like control, will that 5th control pickup the data (maybe on Application Idle event) and not slow down the end user input on any of the 4 main controls or will I just see the same issue because of the forms all running in the same UI thread. 因此,我的问题是,如果我实现了一个消息队列或类似的控件(wcf),用于将新值发送到控件等电子表格,则第5个控件会拾取数据(也许在Application Idle事件上),而不会减慢最终用户的输入速度吗?这四个主要控件中的任何一个,或者由于表单都在同一UI线程中运行,我是否会看到相同的问题。 I did do a some testing to see if it's any quicker if the 5th control is hidden from view, but I see the same results. 我确实做了一些测试,以查看是否从视图中隐藏了第5个控件是否更快,但是我看到了相同的结果。 Also I did some timing checks and it is definitely after I raise the Value_Changed event that the system is becomes very slow. 我也做了一些计时检查,并且肯定是在引发Value_Changed事件之后,系统变得非常缓慢。

Any ideas on how to approach and solve this issue? 关于如何解决这个问题有什么想法吗?

Perhaps you should try a simple Control.BeginInvoke() to pass the data with a structure. 也许您应该尝试一个简单的Control.BeginInvoke()来传递具有结构的数据。 This will ensure you don't have threading issues between objects AND is asynchronous. 这将确保您在对象之间没有线程问题并且是异步的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM