iwant to create dynamic task.delay()..Below is my code snippet .please help me.i am new in xamarin

vipul_008vipul_008 INMember

for (int i = 1; i < splitComandsLight.Length; i++)
{
var r = new Random();

                            var clientTCP = new TcpSocketClient();
                            await clientTCP.ConnectAsync(XMLDeserializationService.XmlData.Connection.gatewayip, XMLDeserializationService.XmlData.Connection.gatewayport);
                            var nextByte = (byte)r.Next(0, 254);
                            byte[] outStream = System.Text.Encoding.UTF8.GetBytes(":" + splitComandsLight[i]);
                            await clientTCP.WriteStream.WriteAsync(outStream, 0, outStream.Length);
                            await clientTCP.WriteStream.FlushAsync();
                            int delayCommandTime = 0;
                            if (splitComandsLight[i].Contains(":TD"))
                            {
                                string delayCommand = splitComandsLight[i];
                                 delayCommandTime = Convert.ToInt32(delayCommand.Substring(3));
                                await Task.Delay(delayCommandTime);
                            }
                            if (delayCommandTime <= 0)
                            {
                                await Task.Delay(TimeSpan.FromMilliseconds(Convert.ToDouble(IOTPortable.Helpers.Settings.ScenarioDelaySetting)));
                            }
                            else
                            {
                                await Task.Delay(delayCommandTime);
                            }

                            await clientTCP.DisconnectAsync();
                        }

Answers

Sign In or Register to comment.