- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个上下文应用程序,它创建新的 Form
以向用户显示一些信息。为此,该用户可以使用按钮关闭表单。然而,在 90 秒后,表单自行关闭,但首先弹出一个消息框让用户知道。
现在我很难理解为什么 MessageBox 会在表单第一次关闭后每隔 90 秒再次弹出。
我有一个用于 90 秒自动关闭并使用 Form.Close 关闭它的 Windows.Forms.Timer。我将表单添加到字典中,其中包含一些管理内容的 ID。
创建表单:
MainForm myform = new MainForm();
myform.plate = eventData.iPlate;
myform.tag = eventData.iTag;
formulario.image = eventData.Image;
formulario.PopulateMyFields();
ActivePopUps.Add(eventData.ide, myform);
myform.Show();
现在使用字典关闭它们
foreach (var popup in ActivePopUps)
{
if (popup.Key == eventData.some_id)
{
try
{
popup.Value.Close();
}
catch { }
ActivePopUps.Remove(popup.Key);
}
}
以及在 MainForm 中创建的计时器
mytimer = new System.Windows.Forms.Timer();
timer_mytimer .Interval = Properties.Settings.Default.ClosingTime; // 90000
mytimer.Tick+=new EventHandler(mytimerEvent);
mytimer.Enabled = true;
mytimer.Start();
和实际的定时器事件
private void mytimerEvent(object sender, EventArgs e)
{
MessageBox.Show("Hey ! Closing this one");
this.Close();
}
我相信我可以在调用 .Close() 之前停止计时器并使其停止,但我的问题是……Close 不应该这样做吗?甚至调用 .Dispose()?为什么计时器会继续工作,还有什么在后台存活?
最佳答案
只是为了澄清。 Sinatr 在他的评论中提供了正确的答案,所以问题得到了完美的回答,我的代码运行良好。
我在创建计时器时遗漏了以下内容:
this.mytimer = new System.Windows.Forms.Timer(this.components)
通过这样做,计时器链接到表单,以便在表单调用 Close() 时处理它。
关于c# - 窗体。 Form.Close 后定时器不停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43933999/
对于一个科学实验,我写了一个turtle.py ,它会打开一个 800x480 的窗口并绘制一个缓慢增长的黑点。 turtle.py以 C:\Users\kaza>python C:\Users\ka
我开发了一个 swing 应用程序,但每次运行应用程序时都会打开一个新窗口。我希望如果一个窗口已经打开,则其他窗口不允许打开。 最佳答案 Here是一个 Java 单一应用实例的例子: A singl
有没有办法检测主进程中 Electron 的结构? process.platform 似乎也在 x64 机器上返回 win32,我没有在文档中找到任何获取架构的选项。 最佳答案 你试过 process
public short[] HanningWindow(short[] signal_in ,int pos ,int size) { for (int i= pos; i < pos+si
我有一个具有这些属性的 Electron 窗口: mainWindow = new BrowserWindow({ width: 800, height: 600, title: "Aqu
我有一个 Ubuntu 工作站,我正在尝试引导一个 Windows 节点。 Windows 节点在端口 2222 上打开了 ssh。我一直在关注 http://docs.opscode.com/plu
我是一名优秀的程序员,十分优秀!