저는 웹 프로그래밍 (Visual Web Developer의 C#)에 익숙하지 않으며 비 C 프로그래밍 기술도 약간 녹슬 었습니다.실수로 하나 이상의 프로세스 만들기
일부 셀에 사용자 입력을 요구하는 테이블을 만들었고 입력이 제공되면 입력이 프롬프트를 대체합니다. 따라서 테이블은 첫 번째 사람이 주석을 달아 페이지에 액세스 할 수 있습니다. 나중에 주석이 달린 페이지는 다른 사람들이 볼 수 있도록 만들어야하므로 처음으로 완료된 후에 프롬프트없이로드 할 페이지가 필요합니다. 이렇게하려면 사용자를 식별하여 해당 사용자가 편집 가능한 페이지를 가져 오도록하고, 모든 편집 내용을 XML 파일에 저장하고, 다른 사용자가 페이지를 실행하면 테이블 설정이 xml 파일에서 다시 읽혀집니다. 수정 사항
xml 파일에 지속적으로 쓰는 데 문제가 있습니다. 특히 나는 때로는 파일에 액세스하는 하나 이상의 프로세스를 만드는 것 및 내 코드를 업데이트하려고 할 때 런타임 예외가 throw됩니다.
각 페이지로드마다 새 파일을 만들고 싶지 않았기 때문에 정적 클래스를 사용하는 것이 좋습니다. 나는이 방법을 호출하고 그 다음에있다
static class XMLReaderWriter
{
static String fileLocation = "D:\\WebApp\\dashboard.xml";
static XMLReaderWriter()
{
FileStream fs = File.Create(fileLocation);
if (File.Exists(fileLocation))
{
// The opening tag
writeToFile(fileLocation, "<Dashboard>\n");
}
else
{
Exception e = new Exception("Failed to create " + fileLocation);
throw e;
}
}
public static void writeXML(String xml)
{
if(File.Exists(fileLocation))
{
writeToFile(fileLocation, xml);
}
else
{
File.Create(fileLocation);
writeToFile(fileLocation, xml);
}
}
private static void writeToFile(String fileLocation, String xml)
{
StreamWriter sw = new StreamWriter(fileLocation, true);
sw.WriteLine(xml);
sw.Close();
sw.Dispose();
}
public static string readXML(String trendID)
{
StringBuilder result = new StringBuilder("");
if (File.Exists(fileLocation))
{
XDocument xDoc = XDocument.Load(fileLocation);
var image = from id in xDoc.Descendants(trendID) select new
{
source = id.Attribute("image").Value
};
foreach (var imageSource in image)
{
result.AppendLine(imageSource.source);
}
}
return result.ToString();
}
public static void done()
{
// The closing tag
writeToFile(fileLocation, "</Dashboard>");
}
}
과 : 여기에 코드입니다
<asp:Button runat="server" Text="Submit Changes" OnClick="Submit_Click" />
protected void Submit_Click(Object sender, EventArgs e)
{
XMLReaderWriter.done();
}
:
XMLReaderWriter.writeXML("\t<trend id=\"" + trendID +"\">\n\t\t" + innerHTML + "\" />\n\t</trend>");
와 마지막으로 xml 파일에 닫는 태그를 추가 버튼을 제출이
때로는 모든 것이 잘 작동합니다. 비록 잘못된 XML을 생성하는 것으로 보이지만. 하지만 대부분의 경우 xml 파일에 액세스하는 프로세스가 두 개 이상 있습니다.
모든 조언을 주시면 감사하겠습니다.
감사합니다.
감사합니다. 각 페이지 요청이 별도의 스레드라는 것을 알지 못했습니다. 그것은 모든 것을 설명합니다. – Kevin