مشاهده نسخه کامل
: تابع Doevents ؟
Hamid_pro
02-02-2007, 17:34
کسی ميتونه بهم بگه تابع doevents چيکار ميکنه؟
_cracki_
03-02-2007, 00:24
این مثال توضیح بسیار خوبی از این فانکشن عالی هست. امیدوارم کمکی کند !
Do You DoEvents?
Lots of programmers don't even know about Visual Basic's DoEvents function. This is not surprising because few Visual Basic programs need it. DoEvents returns control to the operating system temporarily, allowing it to process other events that may have occurred. In my experience, the only time DoEvents is needed is when a program has code that takes a long time to execute, such as certain complex mathematical calculations. By calling DoEvents at strategic locations in your code you can improve program responsiveness.
To see what I mean, create a Standard EXE project in Visual Basic and place one CommandButton and one TextBox on the form. Then, put the following code in the Command Button's Click event procedure:
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
You can see that the code has one loop within another, loops that will take a few seconds to complete (You may want to adjust the value that the inner loop counts to depending on the speed of your system). Each time the outer loop iterates, the current value of i is displayed in the text box. When the loops are finished, "done" is displayed.
What actually happens when you run the program, however, is that the text box does not change until "done" is displayed. The problem is that the system was so busy executing the loops that the requests to display i in the text box got stalled in Windows queue. When the loops were finished, all these requests were processed, too quickly for you to see on the screen.
Now, place a call to DoEvents in the code, just after the Text1.Text = i statement. When you run the program you will see that the text box "counts up" the values of i, just as you would expect. Calling DoEvents frees up the system to process the request, then returns control to the Visual Basic program.
DoEvents is not without potential problems. For example, if you call DoEvents from a procedure you must be sure that the same procedure cannot be called again before execution returns from the first call - otherwise unpredictable results may occur. Likewise, DoEvents should be avoided if other applications could interact with the procedure in unforeseen ways. Use of a Timer control or isolation of long-running code in an ActiveX component are two other approaches to improving program responsiveness.
دوستان میشه یه خورده واضح تر توضیح بدید ما تازه کارام سر در بیاریم
Hamid_pro
03-02-2007, 17:18
Thnax _cracki_ .Very comprehensive explanation.
Hamid_pro
03-02-2007, 17:37
دوستان میشه یه خورده واضح تر توضیح بدید ما تازه کارام سر در بیاریم
توضيح فارسيش اين ميشه whisper:
اين تابع برای مدته کوتاهی کنترل رو به سيستم عامل برميگردنه، و اجازه پردازش وقايع ديگه رو بهش ميده.
مثالش همين کده زيره:
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
بعد از اجرا شدن اين کد، ما فقط 'done' رو ميبينيم، چون برنامه ابتدا حلقه ها رو اجرا ميکنه و در نهايت توی textbox نشون ميده که خيلی سريعه.
حالا اگه يک doevents بعد از text1.text = i اضافه کنيم، ميتونيم تغييرخروجی رو ببينيم.
black_storm
03-02-2007, 20:28
ببین کار به روز رسانی رویداد ها را انجام میده !
-------------------------
a_mohammadi_m
04-02-2007, 13:39
بعضي برنامه ها پردازش سنگيني به سيستم تحميل مي كنند
اين دستور به ويندوز تنفس مي ده تا كارهاي ديگه كامپيوتر رو هم انجام بده
يعني برنامه مذكور اجازه مي ده Cpu به برنامه هاي ديگه و سخت افزارها هم وقت بده
یه جور ساده ترم من بگم . اگر برنامت تویه حلقه ای بیوفته که تمام کارهای ویندوز مختل به قول خودومون سیستم هنگ کنه با استفاده از این دستور از هنگ کردن کامپیوتر جلوگیری می کنی .
vBulletin , Copyright ©2000-2025, Jelsoft Enterprises Ltd.