Hi,
I am fairly new to C# but learning quickly (ex Delphi coder and C coder).
So far I have managed to learn allot without digging into books etc however I want to know how to do things the proper way so I can then learn my own solutions to a problem.
Currently I am working on a small Windows application that monitors various services on a series of remote machines. So far I have been able to create a class that monitors each service and reports the state and also some classes to read/write to a text log file and insert events in the Windows Eventlog.
The data is read in via an XML file and I am using the DataSet class to handle the file; everything works so far i.e I am able to enumerate through the XML file and then based on the whats found (e.g remote hostname, ip address and services), I can then call my service monitor function to go check the machine and then report back its findings.
However I am not too clear on how to do the error handling, so far I have been playing about with the Try..catch..finally code but not having much luck as I seem to be dereferencing something along the way (I miss Delphi
). Here is the offending line:
I encolsed the above in a Try..catch..finally statement and then used tested this in seperate file to ensure the error handling worked (I moved the source xsd file), and sure enough my custom error message popped up "File is not matey!". However when I then tested the same in the main class I was not able to compile the code.
Outside of the Try..catch code I have the following lines to then read the data in the xml file:
When building I get an error advising no reference was found in my main class for xmlschemafile.
I am sure this is a no brainer for someone, I am not an active coder, I simply design solutions to help my main role as a system admin.
Thanks in advance,
Fz
I am fairly new to C# but learning quickly (ex Delphi coder and C coder).
So far I have managed to learn allot without digging into books etc however I want to know how to do things the proper way so I can then learn my own solutions to a problem.
Currently I am working on a small Windows application that monitors various services on a series of remote machines. So far I have been able to create a class that monitors each service and reports the state and also some classes to read/write to a text log file and insert events in the Windows Eventlog.
The data is read in via an XML file and I am using the DataSet class to handle the file; everything works so far i.e I am able to enumerate through the XML file and then based on the whats found (e.g remote hostname, ip address and services), I can then call my service monitor function to go check the machine and then report back its findings.
However I am not too clear on how to do the error handling, so far I have been playing about with the Try..catch..finally code but not having much luck as I seem to be dereferencing something along the way (I miss Delphi
Code:
FileStream xmlschemafile = new FileStream("remotehosts.xsd",FileMode.Open,
FileAccess.Read,FileShare.Read);
Outside of the Try..catch code I have the following lines to then read the data in the xml file:
Code:
ds.ReadXmlSchema(xmlschemafile);
xmlschemafile.Close();
I am sure this is a no brainer for someone, I am not an active coder, I simply design solutions to help my main role as a system admin.
Thanks in advance,
Fz