社区
C#
帖子详情
timer 事件失效
miaojuan666
2010-09-14 11:56:46
情形一
主窗体FormA在Socket异步通信接收信息,若有报警信息,调用弹出窗体(FormB),FormB中有个Timer来控制窗体的弹出和慢慢的退去。但是窗体没有满满弹出,Timer的事件不再执行。
情形二
若一开始我用FormA的一个按钮来控制窗体的弹出,正常弹出,前提是没有用过情形一
情形三
如果已经有通过Socket消息触发的方式调用过FormB,情形二再按那个按钮FormB也无法弹出
好像Timer失效了一样,请高手帮忙分析一下,不胜感激!
...全文
234
7
打赏
收藏
timer 事件失效
情形一 主窗体FormA在Socket异步通信接收信息,若有报警信息,调用弹出窗体(FormB),FormB中有个Timer来控制窗体的弹出和慢慢的退去。但是窗体没有满满弹出,Timer的事件不再执行。 情形二 若一开始我用FormA的一个按钮来控制窗体的弹出,正常弹出,前提是没有用过情形一 情形三 如果已经有通过Socket消息触发的方式调用过FormB,情形二再按那个按钮FormB也无法弹出 好像Timer失效了一样,请高手帮忙分析一下,不胜感激!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jianshao810
2010-09-14
打赏
举报
回复
贴代码吧。事件没触发?
河北瑾航科技
2010-09-14
打赏
举报
回复
弹出代码执行了吗,设置断点执行一下
malun666
2010-09-14
打赏
举报
回复
首先确认:Timer的属性:enable为true时 事件才会响应。
其次是:可以使用多线程弹窗提示
glest
2010-09-14
打赏
举报
回复
[Quote=引用 6 楼 miaojuan666 的回复:]
高手帮忙分析一下
我跟踪了一下timer,发现事件发生异常
由于以前的函数求值超时,函数求值被禁用。必须继续执行才能重新启用函数求值。
我在formLoad里面都使用了
System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;
结果还是不行
[/Quote]
不要使用System.Windows.Forms.Timer控件,换成System.Timers.Timer对象。
原因前者在主线程堵塞时,停止响应;而后者不占用主线程,因此总能触发。
miaojuan666
2010-09-14
打赏
举报
回复
高手帮忙分析一下
我跟踪了一下timer,发现事件发生异常
由于以前的函数求值超时,函数求值被禁用。必须继续执行才能重新启用函数求值。
我在formLoad里面都使用了
System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;
结果还是不行
miaojuan666
2010-09-14
打赏
举报
回复
贴点原代码如下
弹出窗体:
public TaskbarNotifier()
{
timer.Enabled = true;
timer.Tick += new EventHandler(timer_Tick);
}
public void Show(string strTitle, string strContent, int nTimeToShow, int nTimeToStay, int nTimeToHide)
{
WorkAreaRectangle = Screen.GetWorkingArea(WorkAreaRectangle);
titleText = strTitle;
contentText = strContent;
nVisibleEvents = nTimeToStay;
CalculateMouseRectangles();
// We calculate the pixel increment and the timer value for the showing animation
int nEvents;
if (nTimeToShow > 10)
{
nEvents = Math.Min((nTimeToShow / 10), BackgroundBitmap.Height);
nShowEvents = nTimeToShow / nEvents;
nIncrementShow = BackgroundBitmap.Height / nEvents;
}
else
{
nShowEvents = 10;
nIncrementShow = BackgroundBitmap.Height;
}
// We calculate the pixel increment and the timer value for the hiding animation
if (nTimeToHide > 10)
{
nEvents = Math.Min((nTimeToHide / 10), BackgroundBitmap.Height);
nHideEvents = nTimeToHide / nEvents;
nIncrementHide = BackgroundBitmap.Height / nEvents;
}
else
{
nHideEvents = 10;
nIncrementHide = BackgroundBitmap.Height;
}
taskbarState = TaskbarStates.hidden;
bool aaa = false;
switch (taskbarState)
{
case TaskbarStates.hidden:
taskbarState = TaskbarStates.appearing;
SetBounds(WorkAreaRectangle.Right - BackgroundBitmap.Width - 17, WorkAreaRectangle.Bottom - 1, BackgroundBitmap.Width, 0);
timer.Interval = nShowEvents;
timer.Start();
// We Show the popup without stealing focus
aaa=ShowWindow(this.Handle, 5);
break;
case TaskbarStates.appearing:
Refresh();
break;
case TaskbarStates.visible:
timer.Stop();
timer.Interval = nVisibleEvents;
timer.Start();
Refresh();
break;
case TaskbarStates.disappearing:
timer.Stop();
taskbarState = TaskbarStates.visible;
SetBounds(WorkAreaRectangle.Right - BackgroundBitmap.Width - 17, WorkAreaRectangle.Bottom - BackgroundBitmap.Height - 1, BackgroundBitmap.Width, BackgroundBitmap.Height);
timer.Interval = nVisibleEvents;
timer.Start();
Refresh();
break;
}
}
#region TaskbarNotifier Events Overrides
private void timer_Tick(object sender, EventArgs e)
{
switch (taskbarState)
{
case TaskbarStates.appearing:
if (Height < BackgroundBitmap.Height)
SetBounds(Left, Top - nIncrementShow, Width, Height + nIncrementShow);
else
{
timer.Stop();
Height = BackgroundBitmap.Height;
timer.Interval = nVisibleEvents;
taskbarState = TaskbarStates.visible;
timer.Start();
}
break;
case TaskbarStates.visible:
timer.Stop();
timer.Interval = nHideEvents;
// Added Rev 002
if ((bKeepVisibleOnMouseOver && !bIsMouseOverPopup) || (!bKeepVisibleOnMouseOver))
{
taskbarState = TaskbarStates.disappearing;
}
//taskbarState = TaskbarStates.disappearing; // Rev 002
timer.Start();
break;
case TaskbarStates.disappearing:
// Added Rev 002
if (bReShowOnMouseOver && bIsMouseOverPopup)
{
taskbarState = TaskbarStates.appearing;
}
else
{
if (Top < WorkAreaRectangle.Bottom)
SetBounds(Left, Top + nIncrementHide, Width, Height - nIncrementHide);
else
Hide();
}
break;
}
}
主窗体调用
#region 获取信息
private void sockUDP1_DataArrival(byte[] Data, IPAddress Ip, int Port)
{
................
taskbarNotifier1.Show(strData[0], strAlarm, 500, 10000, 500);
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
taskbarNotifier1.Show("111", "222", 500, 10000, 500);
}
当时钟
事件
声明为过程变量 让system.threading.
timer
时钟
失效
这个项目的小模块就是画label 控件到tablepayoutpanel表单 之中, 中间用到了时钟,
事件
(带返回值的),哈希表 。由于时钟定义在 form1的启动构造函数中导致了form1,启动完毕之后时钟停止运行,结果画label画到一半就停了,查找问题,甚是头大,后经大神帮忙,发现了过程变量的问题,在此总结。主要看红字标出部分 public Form1() { ...
C#
Timer
定时任务
C#中,
Timer
是一个定时器,它可以按照指定的时间间隔或者指定的时间执行一个
事件
。 指定时间间隔是指按特定的时间间隔,如每1分钟、每10分钟、每1个小时等执行指定
事件
; 指定时间是指每小时的第30分、每天10:30:30(每天的10点30分30秒)等执行指定的
事件
; 在上述两种情况下,都需要使用
Timer
.Interval,方法如下: 1、按特定的时间间隔: using Sy...
STM32G474 HRTIME PWM 消隐功能
失效
与
事件
优先级冲突的深度解析
本文深入解析了STM32G474高精度定时器HRTIM在PWM应用中出现的消隐功能
失效
与
事件
优先级冲突问题。通过实际案例和详细的技术分析,揭示了丢波现象的根本原因,并提供了移设Set
事件
位置和双保险配置策略等解决方案,帮助工程师优化数字电源和电机控制设计。
Android中使用
Timer
配合postInvalidate()刷新View
在一个没有使用线程 的小游戏 中想刷新一下时间进度,想到用
Timer
。于是写了一段代码 :
nStartRoundTime = System.currentTimeMillis();
nT1 = new
Timer
();
nT1.schedule(new
Timer
Task(){ //计划运行 时间间隔
public void run(){<
LVGL
事件
系统避坑指南:为什么你的按键回调有时不触发?
本文深入剖析LVGL
事件
系统中按键回调不触发的六大常见陷阱,包括输入驱动注册、焦点组绑定、
事件
掩码设置、内存管理、
事件
冒泡及任务循环阻塞。重点解析了按键
事件
从硬件输入到回调执行的完整流程,并提供GDB调试与
事件
监听等实战排查技巧,帮助开发者快速定位并解决问题。
C#
111,129
社区成员
642,540
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章