웹 서비스의 클래스 인 경우 매우 간단한 로그인 시스템을 만들려고합니다. 나는 ham에 createAccounts()가 checkCredentials가 호출 될 때마다 무한한 시간을 계속 가져 오는 문제가있다. 왜 그런가? 자주 요청 times.when웹 서비스에서 무한 시간 호출되는 메서드
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.IO;
public class Service : IService
{
static String path = @"PATH REMOVED";
List<Account> accounts = new List<Account>();
StreamWriter sw = null;
private void createAccounts()
{
String data = File.ReadAllText(path);
string[] data2 = data.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
string[] temp;
for (int i = 0; i < data2.Length; i++)
{
temp = data2[i].Split(',');
if(!usernameExists(temp[0]) && temp[0] != "")
{
accounts.Add(new Account(temp[0],temp[1]));
}
}
}
public bool CreateAccount(String username, String password)
{
createAccounts();
sw = File.AppendText(path);
if (!usernameExists(username))
{
sw.WriteLine(username + "," + password + "\n");
sw.Close();
sw = null;
return true;
}
else
{
sw.Close();
sw = null;
return false;
}
}
public bool usernameExists(String username)
{
createAccounts();
if(accounts.Exists(a => a.username == username))
return true;
else
return false;
}
public bool CheckCredentials(String username, String password)
{
createAccounts();
if (usernameExists(username))
{
if(accounts.Find(a => a.username == username).username == username && accounts.Find(a => a.username == username).password == password)
return true;
else
return false;
}
else
return false;
}
}
class Account
{
public String username;
public String password;
public Account(String u, String p)
{
username = u;
password = p;
}
}
'CheckCredentials'를 호출하는 코드를 실제로 보여 주면 도움이 될 것입니다. –
난 그냥이 작업을 테스트하고 아무것도 다른 콘솔 프로그램을 사용하고있다. – dspiegs
함수가 정확하게 '1 x infinity'라고 정확히 어떻게 계산 되었는가? pantaloonillion과 같이 단순히 많은 횟수가 아닌가? –