C#DateTimePicker陷入循环 [英] C# DateTimePicker stuck in loop

查看:66
本文介绍了C#DateTimePicker陷入循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中有一个datetimepicker。当我单击它时,它将展开以显示每月日历,当我单击向左箭头以返回一个月时,它将更改值并调用我的事件。该事件包含太多代码以供此处包括,但它无需调用就调用了几个函数。

我遇到的问题是,当我单击该左箭头时,它陷入了某种循环并不断下降几个月来,我无法阻止它。被调用的函数之一包含Application.DoEvents(),如果我注释掉它不会陷入循环,但是我需要该命令来更新接口的另一部分。知道为什么会这样吗?

I have a datetimepicker in C#. When I click on it, it expands to show a monthly calendar, when I click the left arrow to go back a month, it changes the value and calls my event. The event includes too much code to include here but it calls several functions needless to say.
The problem I'm having is that when I click that left arrow it gets stuck in some sort of loop and keeps descending through the months and I can't stop it. One of the functions that is being called contains a Application.DoEvents() and if I comment that out it doesn't get stuck in the loop, but I need that command to update another section of the interface. Any idea why this is happening?

我有时可以用这段代码复制它,有时只做几次,有时会陷入循环。

I can duplicate it sometimes with this code, sometimes it just does it a couple times, sometimes it gets stuck in the loop.

private void DateTimePickerValueChangedEvent(object sender, EventArgs e) 
{ 
afunction(); 
} 

private void afunction() 
{ 
listView1.Clear(); 
panel1.Visible = true; 
Application.DoEvents(); 
} 


推荐答案

我也有同样的问题。就我而言,不是更新DoEvents,而是更新Crystal Report视图。我发现的唯一解决方法是在CloseUp事件上更新我的视图,而不是在ValueChanged或TextChanged上更新视图。

I also have the same problem. In my case, instead of calling DoEvents I'm updating a Crystal Report view. The only workaround I found is to update my view upon the CloseUp event instead of ValueChanged or TextChanged.

Scott,您最后是如何纠正问题的?

Scott, how did you finally corrected your problem ?

这篇关于C#DateTimePicker陷入循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆