I create a program that need to received some picture using socket programming, and coding for receiving picture is in background worker.
I need to make progress bar to show how much data I have received. my code still error...
here's my code for received data :
ProgressBar1.Minimum = 0 ProgressBar1.Maximum = 100 If arrayTeks(3) <> Nothing And arrayTeks(6) <> Nothing Then x = arrayTeks(0) + 1 For var = i To x Dim PACKET_SIZE As UInt16 = 4096 Dim Reader As BinaryReader Dim ReadBuffer(PACKET_SIZE - 1) As Byte Dim NData As Int32 Dim MStream As MemoryStream Dim LData As Int32 Reader = New BinaryReader(clientSocket.GetStream) ' Read Length of data (Int32) NData = Reader.ReadInt32 ' Now comes the data, save it in a memory stream MStream = New MemoryStream While NData > 0 LData = clientSocket.GetStream.Read(ReadBuffer, 0, PACKET_SIZE) MStream.Write(ReadBuffer, 0, LData) NData -= LData ' to add progress bar value progressbar1.value += 5 End While ' if all data finish received, showing full progress bar progressbar1.value = 100 SaveFile(arrayTeks(z), MStream.ToArray, False) 'Then z = z + 3 Next End If
error message :
"Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on."
ho do I solve this ??