Parallel.For error - c#

Im trying to pare a DateTime in a Parallel.For:
part of the code:
public void LoadLogFile(String fileName) {
//Thread.CurrentThread.Priority = ThreadPriority.Lowest;
String currentFile = "";
if (fileName.Contains("Compass")) {
currentFile = "Compass";
CompassLogLoadCompleted = false;
compassLogCollection.Clear();
compassLogCollection.AsParallel();
} else if (fileName.Contains("")) {
currentFile = "CoreService";
CoreServiceLogLoadCompleted = false;
coreServiceLogCollection.Clear();
;
compassLogCollection.AsParallel();
} else {
Console.Out.WriteLine("Wrong File");
}
if (fileName.Contains("CoreService") ||
fileName.Contains("Compass")) {
int numberOfSingleLineLog = 0;
int numberOfmultipleLineLog = 0;
String[] lines = new string[] {};
String temp = "";
string[] parts;
DateTime dateTime = new DateTime();
LoggingLvl loggingLvl = new LoggingLvl();
LoggingLvl.ELoggingLvl eLoggingLvl = new LoggingLvl.ELoggingLvl();
int id = 0;
char[] delimiters = new[] {' '};
string threadId = "";
string loggingMessage;
string loggingMessage2 = "";
//string dateAndTimestamp = "";
int ff = 0;
// Read the File and add it to lines string
try {
swCompass.Start();
lines = File.ReadAllLines(fileName);
swCompass.Stop();
} catch (Exception e) {
CompassLogLoadCompleted = true;
CoreServiceLogLoadCompleted = true;
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
swCompass.Reset();
swCompass.Start();
// Adding the objects to the collections
//compassLogCollection.EnableNotify = false;
Parallel.For(0, lines.Count(), j => {
//for (int i = 0; i < lines.Count(); i++) {
string dateAndTimestamp = "";
if (!CompassLogLoadCompleted || !CoreServiceLogLoadCompleted) {
try {
if (SingleLined(ref lines, j)) {
parts = lines[j].Split(delimiters,
StringSplitOptions.
RemoveEmptyEntries);
numberOfSingleLineLog++;
foreach (string t in parts) {
switch (ff) {
case 0:
dateAndTimestamp = t;
break;
case 1:
dateAndTimestamp += " " + t.Replace(",", ".");
dateTime = DateTime.Parse(dateAndTimestamp);
//dateTime = new DateTime();
dateAndTimestamp = "";
break;
case 2:
eLoggingLvl = loggingLvl.ParseLoggingLvl(t);
break;
case 3:
threadId = t;
break;
default:
temp += t;
break;
}
ff++;
}
loggingMessage = temp;
temp = "";
ff = 0;
id++;
loggingLvl = new LoggingLvl(eLoggingLvl);
if (fileName.Contains("Compass")) {
//CompassLogLoadPercent = ((double) numberOfSingleLineLog/lines.Count())*100;
CompassLogData cLD =
new CompassLogData(
(numberOfSingleLineLog +
numberOfmultipleLineLog),
dateTime,
loggingLvl, threadId,
loggingMessage);
//await addRoCompassLogCollectionAsync(cLD);
compassLogCollection.Add(cLD);
} else if (fileName.Contains("CoreService")) {
CoreServiceLogData cSLD =
new CoreServiceLogData(
(numberOfSingleLineLog +
numberOfmultipleLineLog),
dateTime,
loggingLvl,
threadId,
loggingMessage);
//await addRoCoreServiceCollectionAsync(cSLD);
coreServiceLogCollection.Add(cSLD);
} else {
Console.Out.WriteLine("File Not recognizable ");
}
//Console.Out.WriteLine(loggingMessage);
//loggingMessage = "";
} else {
loggingMessage2 += lines[j];
loggingMessage2 += "\n";
//parts[i] += lines[i];
//parts[i] += "\n";
if (NextLineIsANumber(ref lines, j)) {
numberOfmultipleLineLog++;
//Console.Out.WriteLine(loggingMessage2);
parts = loggingMessage2.Split(delimiters,
StringSplitOptions.
RemoveEmptyEntries);
foreach (string t in parts) {
switch (ff) {
case 0:
dateAndTimestamp = t;
break;
case 1:
dateAndTimestamp += " " +
t.Replace(",", ".");
//dateTime = DateTime.Parse(dateAndTimestamp);
dateTime = new DateTime();
dateAndTimestamp = "";
break;
case 2:
eLoggingLvl =
loggingLvl.ParseLoggingLvl(t);
break;
case 3:
threadId = t;
break;
default:
temp += t;
break;
}
ff++;
}
loggingMessage = temp;
temp = "";
ff = 0;
id++;
loggingLvl = new LoggingLvl(eLoggingLvl);
if (fileName.Contains("Compass")) {
CompassLogData cLD =
new CompassLogData(
(numberOfSingleLineLog +
numberOfmultipleLineLog),
dateTime,
loggingLvl, threadId,
loggingMessage);
//await addRoCompassLogCollectionAsync(cLD);
compassLogCollection.Add(cLD);
} else if (fileName.Contains("CoreService")) {
CoreServiceLogData cSLD =
new CoreServiceLogData(
(numberOfSingleLineLog +
numberOfmultipleLineLog),
dateTime,
loggingLvl,
threadId,
loggingMessage);
//await addRoCoreServiceCollectionAsync(cSLD);
coreServiceLogCollection.Add(cSLD);
} else {
Console.Out.WriteLine("File Not recognizable ");
}
loggingMessage2 = "";
}
}
} catch (Exception e) {
Console.Out.WriteLine("Shit Happens");
Console.Out.WriteLine(e.StackTrace);
}
if (currentFile == "Compass") {
//CompassLogLoadPercent =
// ((double)
// i
// /lines.Count())*100;
CompassLogLoadPercent = ((double)
j
/lines.Count())*100;
} else if (currentFile == "CoreService") {
CoreServiceLogLoadPercent =
((double)
j
/lines.Count())*100;
}
}
});
//}
//compassLogCollection.EnableNotify = true;
//compassLogCollection.notifyAll();
if (currentFile == "Compass") {
Console.Out.WriteLine("Compass TIME: " + swCompass.Elapsed);
} else {
Console.Out.WriteLine("CoreSevice TIME: " + swCompass.Elapsed);
}
if (currentFile == "Compass") {
CompassLogLoadCompleted = true;
Console.Out.WriteLine("Compass LOADING DONE");
} else if (currentFile == "CoreService") {
CoreServiceLogLoadCompleted = true;
Console.Out.WriteLine("CoreService LOADING DONE");
}
//CoreServiceLogLoadCompleted = true;
Console.Out.WriteLine("numberOfSingleLineLog: " +
numberOfSingleLineLog);
Console.Out.WriteLine("numberOfmultipleLineLog: " +
numberOfmultipleLineLog);
Console.Out.WriteLine("numberOfLogs: " +
(numberOfSingleLineLog +
numberOfmultipleLineLog));
Console.Out.WriteLine("");
//}
}
}
but i get the following Exception:
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.DateTime.Parse(String s)
at LogViewerV1.LogSession.<>c__DisplayClass3.<LoadLogFile>b__0(Int32 i) in c:\Users\Reza\Documents\Visual Studio 2012\Projects\Pallas informatik\LogViewerV1\LogViewerV1\src\LogSession.cs:line 169
A first chance exception of type 'System.FormatException' occurred in mscorlib.d
If I run this in a ordinary for loop i dont get any exception and everything works fine.
any Idea how to fix This?

FormatException would indicate that the input DateTime is not in the expected format. You should be using the overloads of DateTime.Parse which allow you to specify the DateTypeStyle.
See http://msdn.microsoft.com/en-us/library/system.datetime.parse.aspx#Parse1_Example

I think the problem is that you somehow set the culture of the main thread. But culture is not copied to any other thread, so the background threads that run (parts of) the Parallel.For() loop have different culture.
What you should do is to explicitly specify the culture to use:
DateTime.Parse(dateAndTimestamp, theCorrectCulture)

Related

Reading /proc/stat values to get cpu usage throws DivideByZeroException

I have been following this stack overflow article :
Accurate calculation of CPU usage given in percentage in Linux?
It is written in different language so I decided to follow the logic and convert it to C#.
public class HardwareInfoManager : IHardwareInfoManager
{
private IConfiguration Configuration;
private List<long> oldCpuStatistics;
private List<long> newCpuStatistics;
public HardwareInfoManager(IConfiguration Configuration)
{
this.Configuration = Configuration;
oldCpuStatistics = new List<long>();
newCpuStatistics = new List<long>();
}
private decimal GetCPUUsage()
{
string cpuUsagePath = "//proc//stat";
StringBuilder sb = new StringBuilder();
if (File.Exists(cpuUsagePath) && oldCpuStatistics.IsNullOrEmpty())
{
SaveIntsFromFilePath(cpuUsagePath, oldCpuStatistics);
Task.Delay(200);
GetCPUUsage();
}
if (File.Exists(cpuUsagePath) && !oldCpuStatistics.IsNullOrEmpty())
{
SaveIntsFromFilePath(cpuUsagePath, newCpuStatistics);
var prevIdle = oldCpuStatistics[3] + oldCpuStatistics[4];
decimal idle = newCpuStatistics[3] + newCpuStatistics[4];
var prevNonIdle = oldCpuStatistics[0] + oldCpuStatistics[1] + oldCpuStatistics[2] + oldCpuStatistics[5] + oldCpuStatistics[6] + oldCpuStatistics[7];
decimal nonIdle = newCpuStatistics[0] + newCpuStatistics[1] + newCpuStatistics[2] + newCpuStatistics[5] + newCpuStatistics[6] + newCpuStatistics[7];
var prevTotal = prevIdle + prevNonIdle;
decimal total = idle + nonIdle;
var totalDifference = total - prevTotal;
var idleDifference = idle - prevIdle;
decimal cpuPercentage = (totalDifference - idleDifference / totalDifference) * 100;
cpuPercentage = Math.Round(cpuPercentage, 2);
return cpuPercentage;
}
else
{
return 0;
}
}
private List<long> SaveIntsFromFilePath(string path, List<long> longList)
{
var firstLineOfCPUFile = File.ReadAllLines(path).First();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < firstLineOfCPUFile.Length; i++)
{
//take first index of a number until it reaches a whitespace, add to an int array
if (Char.IsNumber(firstLineOfCPUFile[i]))
{
sb.Append(firstLineOfCPUFile[i]);
//start with this index until it reaches whitespace
}
if (Char.IsWhiteSpace(firstLineOfCPUFile[i]) && i > 5)
{
longList.Add(long.Parse(sb.ToString()));
sb.Clear();
//start with this index until it reaches whitespace
}
}
sb.Clear();
return longList;
}
}
Unable to debug this as it runs on a remote raspberry machine , it throws this error:
Job HardwareInfo.HardwareInfo threw an exception.
Quartz.SchedulerException: Job threw an unhandled exception. --->
System.DivideByZeroException: Attempted to divide by zero.
95% of the time it throws the exception because of the totaldifference being 0. In the other cases it works and throws the whole info such as this:
"TenantId":null,"Hostname":"DEV1\n","Temperature":66.218,"MemoryStats":{"MemoryTotal":"1985984
kB","MemoryFree":"1072468 kB","MemoryAvailable":"1438552
kB"},"CPUUsage":0.0
Please advise, I am stuck for 2 days on this now.
This is how I solved it.
public class HardwareInfoManager : IHardwareInfoManager
{
private IConfiguration Configuration;
private List<long> oldCpuStatistics;
private List<long> newCpuStatistics;
public HardwareInfoManager(IConfiguration Configuration)
{
this.Configuration = Configuration;
oldCpuStatistics = new List<long>();
newCpuStatistics = new List<long>();
}
public HardwareInfoDto GetHardWareInfo()
{
return new HardwareInfoDto()
{
TenantId = Configuration.GetValue<string>("TenantId"),
Hostname = GetHostName(),
Temperature = GetTemperature(),
MemoryStats = GetMemoryStats(),
CPUUsage = GetCPUUsage()
};
}
private string GetHostName()
{
string hostNameFilePath = "//etc//hostname";
if (File.Exists(hostNameFilePath))
{
return (File.ReadAllText(hostNameFilePath));
}
else
{
return "";
}
}
private decimal GetTemperature()
{
string temperatureFilePath = "//sys//class//thermal//thermal_zone0//temp";
if (File.Exists(temperatureFilePath))
{
decimal output = Convert.ToDecimal(File.ReadAllText(temperatureFilePath));
output /= 1000;
//string temperature = output.ToString() + "°C";
return output;
//var file= File.ReadAllLines();
}
else
{
return 0.00M;
}
}
private MemoryStatsDto GetMemoryStats()
{
MemoryStatsDto memoryStatsDto = new MemoryStatsDto();
string memoryStatsPath = "//proc//meminfo";
if (File.Exists(memoryStatsPath))
{
var file = File.ReadAllLines(memoryStatsPath);
//Skipping all lines we are not interested in
for (int i = 0; i < 3; i++)
{
int firstOccurenceOfDigit = 0;
var memoryLine = file[i];
//index of first number , start the string until the end and store it
for (int j = 0; j < memoryLine.Length; j++)
{
if (Char.IsNumber(memoryLine[j]))
{
firstOccurenceOfDigit = j;
break;
}
}
var memoryValue = memoryLine.Substring(firstOccurenceOfDigit);
switch (i)
{
case 0:
memoryStatsDto.MemoryTotal = memoryValue;
break;
case 1:
memoryStatsDto.MemoryFree = memoryValue;
break;
case 2:
memoryStatsDto.MemoryAvailable = memoryValue;
break;
default: break;
}
}
return memoryStatsDto;
}
else
{
memoryStatsDto.MemoryAvailable = "";
memoryStatsDto.MemoryFree = "";
memoryStatsDto.MemoryTotal = "";
return memoryStatsDto;
}
}
private decimal GetCPUUsage()
{
string cpuUsagePath = "//proc//stat";
StringBuilder sb = new StringBuilder();
if (File.Exists(cpuUsagePath) && oldCpuStatistics.IsNullOrEmpty())
{
oldCpuStatistics = SaveIntsFromFilePath(cpuUsagePath, oldCpuStatistics);
Thread.Sleep(10000);
GetCPUUsage();
}
if (File.Exists(cpuUsagePath) && !oldCpuStatistics.IsNullOrEmpty())
{
newCpuStatistics = SaveIntsFromFilePath(cpuUsagePath, newCpuStatistics);
var prevIdle = oldCpuStatistics[3] + oldCpuStatistics[4];
decimal idle = newCpuStatistics[3] + newCpuStatistics[4];
var prevNonIdle = oldCpuStatistics[0] + oldCpuStatistics[1] + oldCpuStatistics[2] + oldCpuStatistics[5] + oldCpuStatistics[6] + oldCpuStatistics[7];
decimal nonIdle = newCpuStatistics[0] + newCpuStatistics[1] + newCpuStatistics[2] + newCpuStatistics[5] + newCpuStatistics[6] + newCpuStatistics[7];
var prevTotal = prevIdle + prevNonIdle;
decimal total = idle + nonIdle;
var totalDifference = total - prevTotal;
var idleDifference = idle - prevIdle;
decimal cpuPercentage = 0;
Log.Logger.Information($"TotalDifference is {totalDifference}");
Log.Logger.Information($"IdleDifference is {idleDifference}");
cpuPercentage = (totalDifference - idleDifference) * 100M / (totalDifference);
cpuPercentage = Math.Round(cpuPercentage, 2);
return cpuPercentage;
}
else
{
return 0;
}
}
private List<long> SaveIntsFromFilePath(string path, List<long> longList)
{
var firstLineOfCPUFile = File.ReadAllLines(path).First();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < firstLineOfCPUFile.Length; i++)
{
//take first index of a number until it reaches a whitespace, add to an int array
if (Char.IsNumber(firstLineOfCPUFile[i]))
{
sb.Append(firstLineOfCPUFile[i]);
//start with this index until it reaches whitespace
}
if (Char.IsWhiteSpace(firstLineOfCPUFile[i]) && i > 5)
{
longList.Add(long.Parse(sb.ToString()));
sb.Clear();
//start with this index until it reaches whitespace
}
}
sb.Clear();
for (int i = 0; i < longList.Count; i++)
{
Log.Logger.Information($"LongList index {i} value is {longList[i]}");
}
return longList;
}
}

odd text display C#

I have the following code in a windows form:
for (int i = 1; (i <= 10); i++)
{
if ((worker.CancellationPending == true))
{
e.Cancel = true;
break;
}
else
{
try
{
string message = "";
string m = "";
textBox2.Text = "";
int count = 0;
while (TestConnection(client))
{
char tt = ' ';
try
{
tt = Convert.ToChar(sr.Read());
if (count < 4)
{
message = tt.ToString();
m += message;
count += 1;
}
else if (count >= 4)
{
this.Invoke(new BindTextBoxControl(UpdateTextbox), new object[] {m + "\r\n"});
textBox2.Text = m + "\r\n";
m = "";
count = 0;
}
}
catch (OverflowException)
{
m += "";
}
}
}
catch (Exception g)
{
string error = "An error occurred: '{0}'" + g;
}
this gets a continuous stream of data from a StreamReader and then displays the data (4 character string). It is supposed to replace the current string shown with a new one(if the string is rrrr and then i receive tttt it shows tttt) but what it does is remove the first letter of the current string and add the next revived letter (have rrrr get tttt shows rrrt then rrtt and so forth).
how do i get this to work properly?
EDIT:
private void UpdateTextbox(string _Text)
{
textBox1.Text = _Text;
}
delegate void BindTextBoxControl(string text);
Nothing special about these.

How to get output to be a continuous string rather than it being stacked on top of each letter - c#

public class LetterArray
{
internal static string[] Alphabet()
{
var letterValues = new string[26];
letterValues[0] = "A";
letterValues[1] = "B";
letterValues[2] = "C";
letterValues[3] = "D";
letterValues[4] = "E";
letterValues[5] = "F";
letterValues[6] = "G";
letterValues[7] = "H";
letterValues[8] = "I";
letterValues[9] = "J";
letterValues[10] = "K";
letterValues[11] = "L";
letterValues[12] = "M";
letterValues[13] = "N";
letterValues[14] = "O";
letterValues[15] = "P";
letterValues[16] = "Q";
letterValues[17] = "R";
letterValues[18] = "S";
letterValues[19] = "T";
letterValues[20] = "U";
letterValues[21] = "V";
letterValues[22] = "W";
letterValues[23] = "X";
letterValues[24] = "Y";
letterValues[25] = "Z";
return letterValues;
}
}
public class decrypt
{
public static void Main() //Main method
{
int res = 34;
string[] letterValues = LetterArray.Alphabet();
//Create for loop that runs through every possible shift value
for (int shift = 0; shift <= 25; shift++)
{
Console.WriteLine("\nShift Value = " + shift + ": ");
// For each character in the text file
foreach (var ch in ReadText.cipherTxt()) {
if (ch == ' ')
{ }
else
{
for (int i = 0; i <= 25; i++)
{
if ((ch.ToString().ToUpper()) == letterValues[i])
{
res = i;
}
}
if (shift > res)
{
Console.WriteLine(letterValues[26 - (shift - res)][0]);
}
else
{
Console.WriteLine(letterValues[res - shift][0]);
}
}
}
}
}
}
Not sure how to output the following so be a continuous string instead of each letter being stacked on top of each other. I have tried to change the Console.WriteLine values but it seems to mess the program up and throw an error instead.
Use Console.Write if you don't want each value in a new line.
Console.Write(letterValues[res - shift]);
You can also use a StringBuilder and Append characters to it. Then print it once after the loop.

Scanning , Parsing

I'm writing simple compiler without using grammar Generators. Here
. I wrote the scanning code that read file.txt ,and classify it to Identifier or Revers words , Number , Variable ..etc.
I got the result that I want but Is it possible to complete with this code I mean applying syntax Analysis ? and parsing ? . Because I I tried make it with java and I coded it with wrong way . I want see if I do it right ,specially i'm not good in C# codding .
Arrays :
string[] Rw = new string[8];
Rw[0] = "for";
Rw[1] = "while";
Rw[2] = "end";
Rw[3] = "contiune";
Rw[4] = "if";
Rw[5] = "break";
Rw[6] = "do";
Rw[7] = "return";
string[] id = new string[6];
id[0] = "int";
id[1] = "float";
id[2] = "string";
id[3] = "double";
id[4] = "bool";
id[5] = "char";
string[] op = new string[6];
op[0] = "+";
op[1] = "-";
op[2] = "/";
op[3] = "*";
op[4] = "%";
string[] Num = new string[10];
Num[0] = "0";
Num[1] = "1";
Num[2] = "2";
Num[3] = "3";
Num[4] = "4";
Num[5] = "5";
Num[6] = "6";
Num[7] = "7";
Num[8] = "8";
Num[9] = "9";
string[] var = new string[17];
var[0] = "a";
var[1] = "b";
var[2] = "A";
var[3] = "B";
var[4] = "C";
var[5] = "d";
var[6] = "D";
var[7] = "X";
var[8] = "x";
var[9] = "Y";
var[10] = "y";
var[11] = "z";
var[12] = "Z";
var[13] = "v";
var[14] = "V";
var[15] = "f";
var[16] = "F";
Reading and Split :
char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
using (System.IO.StreamReader file = new System.IO.StreamReader(#"C:\Users\caza\Desktop\1.txt"))
{
while ((line = file.ReadLine()) != null)
{
string[] token = line.Split(delimiterChars);
foreach (string s in token)
{
// Console.WriteLine(s);
foreach (string z in Rw)
{
if (s == z)
{
Console.WriteLine(s + " is a Reserved Word ");
}
}
foreach (string y in id)
{
if (s == y)
{
Console.WriteLine(s + " is a identifier ");
}
}
foreach (string o in op)
{
if (s == o)
{
Console.WriteLine(s + " is a Operation ");
}
}
foreach (string n in Num)
{
if (s == n)
{
Console.WriteLine(s + " is a Number ");
}
}
foreach (string v in var)
{
if (s == v)
{
Console.WriteLine(s + " is a Variable");
}
}
}
}
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}

How to prevent stack overflow error in javascript?

I have a javascript function called MakeInput.
It has got approximately 150 lines.
And I have to call that function about 300 times in my code.
My C# code called that function through webbrowser control.
It has to call that function 300 times, until DataTable in C# finishes looping.
But maybe javascript in webbrowser thinks that I am calling an infinite recursive function, so when it comes to about 60 times, it always throws an error called stack overflow at line 38.
How can I prevent this error?
How can I do a long time function in javascript?
EDIT
OK.
I am posting my code.
Here it goes.
C#
ieBrowser.Document.InvokeScript("setPageIndex", new object[] { currentPage });
ieBrowser.Document.InvokeScript("fnSearch");
JavaScript
function fnSearch() {
var frm = document.searchFrm;
var str = encryptData(frm, _currentPage);
}
function encryptData(form, _currentPage) {
var retValue = "";
try {
var crypto = document.getElementById("SomeActiveX");
var resultVal = MakeInput(form);
var inputStr = "";
if (resultVal[0] != "" && resultVal[1] != "") {
inputStr = resultVal[0] + "&" + resultVal[1];
}
else if (resultVal[0] == "") {
inputStr = resultVal[1];
}
else if (resultVal[1] == "") {
inputStr = resultVal[0];
}
else {
inputStr = "";
}
retValue = crypto.Encrypt(inputStr);
}
catch (e) {
alert(e);
}
return retValue;
}
function MakeInput(form) {
var result = new Array(2);
try {
var keyProc = document.getElementById("SomeActiveX");
var name = new Array(form.elements.length);
var value = new Array(form.elements.length);
var enc_name = new Array();
var enc_value = new Array();
var enc_idx = 0;
var j = 0;
var len = form.elements.length;
for (i = 0; i < len; i++) {
if ((form.elements[i].type != "button") && (form.elements[i].type != "reset") &&
(form.elements[i].type != "submit")) {
if ((form.elements[i].type == "radio") || (form.elements[i].type == "checkbox")) {
if (form.elements[i].checked == true) {
name[j] = form.elements[i].name;
value[j] = form.elements[i].value;
j++;
}
}
else if ((form.elements[i].type == "text") || (form.elements[i].type == "password")) {
name[j] = form.elements[i].name;
value[j] = form.elements[i].value;
j++;
if (keyProc != null && (form.elements[i].getAttribute("enc") == "on")) {
enc_name[enc_idx] = "_E2E_" + form.elements[i].name;
enc_value[enc_idx] = keyProc.GetEncData("", form.name, form.elements[i].name);
enc_idx++;
}
}
else {
if (form.elements[i].type == "select-one") {
var ind = form.elements[i].selectedIndex;
var singleLen = form.elements[i].length;
if (singleLen > 0) {
if (ind >= 0) {
name[j] = form.elements[i].name;
value[j] = form.elements[i].options[ind].value;
j++;
}
else {
}
}
else {
}
}
else if (form.elements[i].type == "select-multiple") {
var multiLen = form.elements[i].length;
for (k = 0; k < multiLen; k++) {
if (form.elements[i].options[k].selected) {
name[j] = form.elements[i].name;
value[j] = form.elements[i].options[k].value;
j++;
}
}
}
else {
name[j] = form.elements[i].name;
value[j] = form.elements[i].value;
j++;
}
}
}
}
var flag1 = false;
var flag2 = false;
var signed_text = "";
var unsigned_text = "";
for (i = 0; i < j; i++) {
if (name[i].charAt(0) != "_") {
if (flag1) {
signed_text += "&";
}
else {
flag1 = true;
}
signed_text += name[i];
signed_text += "=";
signed_text += escape_url(value[i]);
}
else {
if (flag2) {
unsigned_text += "&";
}
else {
flag2 = true;
}
unsigned_text += name[i];
unsigned_text += "=";
unsigned_text += escape_url(value[i]);
}
}
for (i = 0; i < enc_idx; i++) {
if (flag2) {
unsigned_text += "&";
}
else {
flag2 = true;
}
unsigned_text += enc_name[i];
unsigned_text += "=";
unsigned_text += enc_value[i];
}
if (enc_idx > 0) {
if (flag2) {
unsigned_text += "&";
}
else {
flag2 = true;
}
unsigned_text += "_ENCSEED";
unsigned_text += "=";
unsigned_text += keyProc.GetEncData(serverCert, "", "");
}
result[0] = signed_text;
result[1] = unsigned_text;
}
catch (e) {
throw e;
}
return result;
}
And the error message was captured.
Sorry, the error message is written in Korean.
But it says, "Stack overflow(at line 38)".
But I think the number is not pointing at the line number, coz I've changed lines but the error message is always 38.
It doesn't think you are in a continuous loop. It fails when memory runs out in stack. The same code might work on a computer with higher memory. Each time a function is called a stack entry is kept in stack to move to calee once the function is done, so in your case the stack space runs out after 60 calls. The line 38 is not line number in your code.
Why dont you try same code on a high end PC

Categories