I am trying to create a web forms application which fetches data from database on clicking a button on the form and then uses that data to hit REST service and finally store items which have OK response. But the service takes approx 3-4 sec to respond to each request and total hits are approx : 80,000 and the forms app starts "not responding" as soon as i start hitting the REST service. PFB code for the app .Any help would be really great.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using RestSharp;
using Newtonsoft.Json;
namespace Test_Data_Generator
{
public partial class Form1 : Form
{
string BaseDevURL = string.Empty;
string BaseSIURL = string.Empty;
string _currentProductItemID = string.Empty;
List<StringValue> ValidProductItemsIDs = new List<StringValue>();
private IRestResponse _response;
private ServiceActions _RESTservice;
private Dictionary<string, string> _requestHeaders;
private DataTable ProductItemIDs;
BindingList<StringValue> blist = new BindingList<StringValue>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
_requestHeaders = new Dictionary<string, string>
{
{"ContentType", "application/json"},
{"Accept", "application/json"}
};
}
private void btnGetTestData_Click(object sender, EventArgs e)
{
//Populate the data table on the basis of radio button which is checked
if (!(rbDev.Checked) && !(rbSI.Checked))
System.Windows.Forms.MessageBox.Show("Please check a radio button for desired environment");
else if (rbDev.Checked)
{
ProductItemIDs = DataBase.GetValues(rbDev.Text);
BaseDevURL = ConfigurationManager.AppSettings["Service DEV"];
}
else if (rbSI.Checked)
{
ProductItemIDs = DataBase.GetValues(rbSI.Text);
BaseSIURL = ConfigurationManager.AppSettings["Service SI"];
}
try
{
dgvDBdata.DataSource = ProductItemIDs;
lblDbValuesCount.Text = ProductItemIDs.Rows.Count.ToString() + " rows";
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception caught : " + ex.Message);
}
}
private void btnGetDataFromRESTService_Click(object sender, EventArgs e)
{
dgvValidPIDs.DataSource = blist;
//Populate the data table on the basis of radio button which is checked
if (!(rbDev.Checked) && !(rbSI.Checked))
System.Windows.Forms.MessageBox.Show("Please check a radio button for desired environment");
else if (rbDev.Checked)
{
_PITSservice = new ServiceActions(BaseDevURL);
}
else if (rbSI.Checked)
{
_PITSservice = new ServiceActions(BaseSIURL);
}
try
{
//Submit Rest request for each ProductItem ID retrieved from DB
for (int i = 1; i < 100; i++ )
{
_currentProductItemID = ProductItemIDs.Rows[i].ToString();
_response = _RESTservice.SubmitRestRequest(
null,
"ProductItemSummaries?ProductItemId=" + _currentProductItemID,
"Get",
DataFormat.Json,
DataFormat.Json,
_requestHeaders);
if (_response.StatusCode.ToString().Contains("OK"))
blist.Add(new StringValue(_currentProductItemID));
dgvValidPIDs.Refresh();
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception caught : " + ex.Message);
}
}
}
public class StringValue
{
string _value;
public StringValue(string s)
{
_value = s;
}
public string Value { get { return _value; } set { _value = value; } }
}
}
Aucun commentaire:
Enregistrer un commentaire