16-10-14, 07:45 AM
.....
جرب التالي (أضف ProgressBar)
.....
جرب التالي (أضف ProgressBar)
كود :
Public Class Form1
' API - SHChangeNotify
<Runtime.InteropServices.DllImport("shell32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto, SetLastError:=True)> _
Public Shared Sub SHChangeNotify(ByVal wEventId As UInt32, ByVal uFlags As UInt32, ByVal dwItem1 As IntPtr, ByVal dwItem2 As IntPtr)
End Sub
'Desktop refresh
Const SHCNE_ASSOCCHANGED = &H8000000
Const SHCNF_IDLIST = &H0
' إنشاء مهمة مع التعريف بعنوان الاجراء الذي سينفذه
Private thrd As New Threading.Thread(AddressOf thrdTask)
'تحديد زمن الانتظار بالثوان
Dim waitseconds As Integer = 10
' تعريفات في بداية التشغيل
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' إلغاء فحص تضارب المهام
Control.CheckForIllegalCrossThreadCalls = False
' عمل المخمة في الخلفية
thrd.IsBackground = True
' بدء المهمة
thrd.Start()
End Sub
' إجراء المهمة
Private Sub thrdTask()
' تحديد قيم البروقرسبار
Me.ProgressBar1.Maximum = waitseconds
Me.ProgressBar1.Value = waitseconds
' إنشاء مؤقت
Dim sw As New Stopwatch()
' بدء المؤقت
sw.Start()
' حلقة لا تنتهي إلا بإنهاء البرنامج
Do
' متغير يحتوي قيمة الثوان الحالية في المؤقت
Dim elapsedSeconds As Integer = sw.Elapsed.Seconds
' تعيين قيمة مؤشر البروقرسبار
Me.ProgressBar1.Value = Math.Abs(waitseconds - elapsedSeconds)
' عندما ثوان المؤقت للزمن المحدد
If elapsedSeconds >= waitseconds Then
' تحديث سطخ المكتب
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero)
' إعادة المؤقت إلى البداية
sw.Reset()
' بدء المؤقت من جديد
sw.Start()
End If
' تجميد المهمة لبعض الوقت لعدم إشغال المعالج على أن لا تزيد عن 1000
Threading.Thread.Sleep(300)
Loop
End Sub
End Class.....



