winform 多个计时器操作问题
过程:现在有2个计时器,分别传不同的指令,向服务器请求,如下代码:
请求
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
c.send("09 20 00 0A", "03");//发送请求指令
ReciveData1();
private void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
c.send("09 34 00 0A", "03");//发送请求指令
ReciveData2();
}
接收:
//从线程池接受响应数据(读T1-T10:Actual)
private void ReciveData1()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(LongTask1));
}
//从线程池接受响应数据(读T1-T10:Setpoint)
private void ReciveData2()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(LongTask2));
}
public void LongTask1(object obj)
{
string[] strReceive = new string[10];
strReceive = c.receive();
this.label65.Text = strReceive[0];
this.label64.Text = strReceive[1];
this.label63.Text = strReceive[2];
this.label62.Text = strReceive[3];
this.label61.Text = strReceive[4];
this.label60.Text = strReceive[5];
this.label59.Text = strReceive[6];
this.label58.Text = strReceive[7];
this.label57.Text = strReceive[8];
this.label56.Text = strReceive[9];
}
public void LongTask2(object obj)
{
string[] strReceive = new string[10];
strReceive = c.receive();
this.label53.Text = strReceive[0];
this.label52.Text = strReceive[1];
this.label51.Text = strReceive[2];
this.label50.Text = strReceive[3];
this.label49.Text = strReceive[4];
this.label48.Text = strReceive[5];
this.label47.Text = strReceive[6];
this.label46.Text = strReceive[7];
this.label45.Text = strReceive[8];
this.label44.Text = strReceive[9];
}
问题:如何通过队列,或者锁,对他们响应的数据进行异步处理。
现在的结果是响应回来的数据,不能异步显示,会产生交叉显示。
如: this.label65.Text =60,......
this.label53.Text =50,......
会出现这样的结果:
this.label65.Text =50,......
this.label53.Text =60,......
相关推荐
事件计时器
很久之前写的了,还有些不友好的地方,但是不想改了啊,想了很久还是上传吧1
C# WinForm计时器停止并重置计时器,该如何处理
例如,如果需要重置计时器的初始值,可以在启动计时器之前将计时器的Value属性重置为初始值。首先,在WinForm窗体中添加一个Timer控件,并设置相应的属性,如Interval(计时器间隔)和Enabled(是否启用计时器)等。在该方法中,根据当前计时器的状态来切换计时器的启用状态以及更新isTimerRunning变量的值。在计时器的Tick事件中编写相应的代码来执行定时任务或计时操作。接下来,我们需要编写相应的代码来处理计时器的停止和重置操作。至此,我们已经完成了计时器的停止和重置功能的实现。
Winform倒计时器实现指南
Winform,全称Windows Forms,是.NET框架中的一个用于构建丰富的客户端Windows应用程序的库。它为开发者提供了丰富的UI元素,如按钮、文本框、下拉列表等,使得创建交互式桌面应用程序变得简单而直观。Winform应用程序基于事件驱动模型,这意味着应用程序的执行流程主要由用户操作触发的事件来驱动。Winform最大的优势之一是它的控件重用性,开发者可以轻松创建自定义控件,并将它们集成到应用程序中。这一特性使得Winform能够满足从简单到复杂的各种应用程序需求。
C# WinForm创建透明无边框计时器项目详解
在传统的 Windows 桌面应用程序中,窗体的边框和标题栏提供了用户与应用程序交互的基本界面元素。标题栏允许用户拖动窗体,调整大小,最小化,最大化和关闭窗口。边框则为窗体提供了一个可感知的边界,这有助于用户识别窗体的边缘并进行精确的控制。它们是 Windows 用户界面的一部分,与操作系统紧密集成,提供了对于应用程序窗口的基本操作功能。为了实现更复杂的自定义边框样式,可以使用 Windows API。
winForm功能集1
winForm功能集1 实用性很强,分为1,2,3,4个部分!还有游戏(俄罗斯方块,华容道,贪吃蛇,五子棋...);


