In essence she was asked to do a dropdown list of users (combobox). After the list is selected by some user, it is added to a specific file, then a field combobox'again freely to enter.
Implementation: In the field combobox'a start to enter the name, there is a drop down list with users whose name coincide with the entered. The matching is implemented through a request to the IPA server(use JIRA), then the resulting list is processed and stored in an array, then the list is displayed in the combobox.
Problem: sometimes the code works consistently, but sometimes, every 4-5 requests the error AccessViolationException "Attempted to read or write protected memory. This often indicates that other memory is corrupt."
I would like to resolve this issue. Before the error appeared more often, I thought that the server blocks the abuse, so the request was to send every 4 characters. Then the problem was forgotten until the program used in the normal operating mode.
public void dropDownList(ComboBox comboBox)
{
comboBox.Text = comboBox.Text;
string text = comboBox.Text;
string url = "https://serverAddress/api/2/user/picker?maxResults=7&query=" + text;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer();
request.Method = "GET";
request.ContentType = "application/json; charset=utf-8";
request.CookieContainer.Add(Session.cookies);
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Stream stream = response.GetResponseStream();
JsonSerializer jsonSerializer = new JsonSerializer();
using (StreamReader reader = new StreamReader(stream))
{
using (JsonTextReader jsonTextReader = new JsonTextReader(reader))
{
var obj = jsonSerializer.Deserialize(jsonTextReader);
string jsonString = @JsonConvert.SerializeObject(obj);
JObject jObject = JObject.Parse(jsonString);
JArray array = (JArray)jObject["users"];
comboBox.Items.Clear();
comboBox.SelectionStart = text.Length;
int count = array.Count;
userArray = new string[count];
string temp = "";
for (int i = 0; i < count; i++)
{
temp = string.Format("{0}", array[i]["html"]);
temp = temp.Replace("strong>", "").Replace("<", "").Replace("/", "");
userArray[i] = temp;
temp = "";
}
comboBox.Items.AddRange(userArray);
Array.Clear(userArray, 0, count);
}
}
}
}
catch
{
MessageBox.Show("something went wrong");
}
}
If so, see system event log subkey application - cole_Rutherford commented on June 8th 19 at 17:34