private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (e.UserState != null)
     {
         WorkReport report = e.UserState as WorkReport;
         if (report != null)
         {
             String json = JsonPrettify(report.Report);
             textBoxResponce.Text = JsonPrettify(json);
             textBoxCurrent.Text  = report.id.ToString();
         }
         else
         {
             String error = e.UserState as String;
             textBoxResponce.Text = error;
         }
         tabControl.SelectedTab = tabPageResponce;
     }
 }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            SendParams sendParam = (SendParams)(e.Argument);
            string     json      = null;
            bool       isError   = false;

            for (int j = 0; j < sendParam.count; j++)
            {
                if (backgroundWorker1.CancellationPending)
                {
                    break;
                }

                try
                {
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sendParam.address);
                    request.ContinueTimeout = 88000;
                    request.ContentType     = "application/json; charset=utf-8";
                    request.Accept          = "application/json, text/javascript, */*";
                    request.Method          = "POST";
                    if (!isBasic_Autotication)
                    {
                        request.Credentials = CredentialCache.DefaultNetworkCredentials;
                    }
                    else
                    {
                        String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(UserName_Authotication + ":" + Password_Authontification));
                        request.Headers.Add("Authorization", "Basic " + encoded);
                        //  request.Credentials = new NetworkCredential(UserName_Authotication, Password_Authontification);
                    }

                    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                    {
                        writer.Write(sendParam.request);
                    }

                    if (backgroundWorker1.CancellationPending)
                    {
                        break;
                    }

                    WebResponse response = request.GetResponse();
                    Stream      stream   = response.GetResponseStream();
                    json = "";

                    using (StreamReader reader = new StreamReader(stream))
                    {
                        while (!reader.EndOfStream)
                        {
                            json += reader.ReadLine();
                        }
                    }

                    WorkReport report1 = new WorkReport
                    {
                        id     = j + 1,
                        Report = json
                    };

                    backgroundWorker1.ReportProgress(j, report1);

                    sendParam.responce = json;
                }
                catch (Exception ex)
                {
                    sendParam.responce = ex.Message;
                    isError            = true;
                    json = ex.Message;
                }
                backgroundWorker1.ReportProgress(j, json);
            }


            if (isError)
            {
                e.Result = sendParam.responce;
            }
            else
            {
                WorkReport report = new WorkReport
                {
                    id     = sendParam.count,
                    Report = json
                };
                e.Result = report;
            }
        }