29-07-17, 04:12 AM
(29-07-17, 02:17 AM)ابو ليلى كتب : السلام عليكم و رحمة الله و بركاته
في ما يبدو انك تستخدم VS 2010 , نسخة اطار العمل 4.0 , و انا اعمل مع النسخة 4.5
و للاسف النسخة 4.0 لا تدعم العمليات غير المتزامنة عبر Async Wait
لذلك اخي الكريم حاول ان تعتمد على Thread لتلبي طلبك.
عدل كود النموذج لديك كالتالي
PHP كود :
Imports System.Threading
Public Class Form1
Dim Th As Thread = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1 To 100
ListBox1.Items.Add("emad" & i)
Next
End Sub
Structure Mystruct
Shared room As String = "Room"
Shared mspv1 = 111
Shared mspv2 = 222
Shared mspv3 = 333
Shared mspv4 = 444
Shared mspv5 = 555
Shared colors = "Red"
End Structure
Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
TextBox1.Clear()
BtnSend.Enabled = False
If ListBox1.Items.Count > 0 Then
ProgressBar1.Maximum = ListBox1.Items.Count - 1
Th = New Thread(Sub()
For x As Integer = 0 To ListBox1.Items.Count - 1
Thread.Sleep(100)
send(0, x)
Next
End Sub)
Th.IsBackground = True
Th.Start()
Else
TextBox1.Text = "<presence to='" & Mystruct.room & "@conference.nimbuzz.com/imanking' type='unavailable'></presence>"
ProgressBar1.Value = 0
BtnSend.Enabled = True
End If
End Sub
Private Sub send(i As Integer, x As Integer)
Dim Sb As New List(Of String)
Sb.Clear()
Me.BeginInvoke(Sub()
If Not Th.IsAlive Then
BtnSend.Enabled = True
End If
Dim Str As String() = {"<message xmlns='jabber:client' to='", Mystruct.room _
, "@conference.nimbuzz.com/", ListBox1.Items(i).ToString, vbNewLine,
"'type='chat' id='292'>", vbNewLine,
"<body>", vbNewLine, Mystruct.mspv1 & vbNewLine &
Mystruct.mspv2 & vbNewLine & Mystruct.mspv3 & vbNewLine &
Mystruct.mspv4 & vbNewLine & Mystruct.mspv5, vbNewLine &
"</body>", vbNewLine, "<html xmlns='http://jabber.org/protocol/xhtml-im'>", vbNewLine,
"<body xmlns='http://www.w3.org/1999/xhtml'>", vbNewLine,
"<p>", vbNewLine, "<em>", vbNewLine, "false", vbNewLine,
"</em>", vbNewLine, "<strong>", vbNewLine, "true", vbNewLine,
"</strong>", vbNewLine, "<span style='" & Mystruct.colors & "'/>", vbNewLine,
"</p>", vbNewLine, "</body>", vbNewLine, "</html>", vbNewLine,
"</message>", vbNewLine, "***********************************"}
Sb.Add(String.Concat(Str))
For Each Instr As String In Sb
TextBox1.AppendText(Instr & Environment.NewLine)
Next
ProgressBar1.Value = x
ListBox1.Items.RemoveAt(0)
'هذا الكود لاظهار التقدم بالنسبة المئوية
Dim percent As Integer = CInt((CDbl(ProgressBar1.Value - ProgressBar1.Minimum) / CDbl(ProgressBar1.Maximum - ProgressBar1.Minimum)) * 100)
Using gr As Graphics = ProgressBar1.CreateGraphics()
gr.DrawString(percent.ToString() + "%", SystemFonts.DefaultFont, Brushes.Black, New PointF(ProgressBar1.Width / 2 - (gr.MeasureString(percent.ToString() + "%", SystemFonts.DefaultFont).Width / 2.0F), ProgressBar1.Height / 2 - (gr.MeasureString(percent.ToString() + "%", SystemFonts.DefaultFont).Height / 2.0F)))
End Using
End Sub)
End Sub
End Class
اعمل خاصية MultiLine =True لمربع النص و قم بتوسيعه حتى تظهر الرسالة بشكل كامل
بالتوفيق
اخي بارك الله فيك ولكن اريد تطبيق التالي
Public Class Form1
Dim emad As XmppClientConnection
بحيث ارسال الكود مرتبط من خلال الاتصال التالي
PHP كود :
Dim Str As String() = {"<message xmlns='jabber:client' to='", Mystruct.room _
, "@conference.nimbuzz.com/", ListBox1.Items(i).ToString, vbNewLine,
"'type='chat' id='292'>", vbNewLine,
"<body>", vbNewLine, Mystruct.mspv1 & vbNewLine &
Mystruct.mspv2 & vbNewLine & Mystruct.mspv3 & vbNewLine &
Mystruct.mspv4 & vbNewLine & Mystruct.mspv5, vbNewLine &
"</body>", vbNewLine, "<html xmlns='http://jabber.org/protocol/xhtml-im'>", vbNewLine,
"<body xmlns='http://www.w3.org/1999/xhtml'>", vbNewLine,
"<p>", vbNewLine, "<em>", vbNewLine, "false", vbNewLine,
"</em>", vbNewLine, "<strong>", vbNewLine, "true", vbNewLine,
"</strong>", vbNewLine, "<span style='" & Mystruct.colors & "'/>", vbNewLine,
"</p>", vbNewLine, "</body>", vbNewLine, "</html>", vbNewLine,
"</message>", vbNewLine, "***********************************"}
Sb.Add(String.Concat(Str))
.........الخDim Str As String() = {"<message
ب
.........الخemad.send(String.Concat(New String() {"<message
ليصبح البرنامج فعال وشكراً
