c# - Sending status message from one class to my Main method -
i have class lengthy foreach
loop may take minute or more run, depending on number of records parsing , inserting, updating,etc..
so have 1 class this:
public class filemaneger { public bool parsefile() { // ....stuff foreach(datarow row in rows) { // stuff } } }
and in program.cs
main method
:
filemanager manager = new filemanager(); console.writeline("parsing started..."); manager.parsefile(); console.writeline("parsing finished.");
so thinking maybe in between of 2 messages can show few more feedback, example put counter in foreach
loop , every 50 rows passes print console message "parsing rows 1 50 6500 rows", "parsing rows 51 100 6500 rows", etc...
so think need write sort of event
not experienced events, can part?
here started. can use delegates.
public class filemaneger { public action<string> trace {get;set;} public bool parsefile() { // ....stuff foreach(datarow row in rows) { // stuff this.trace("send message this"); } } }
then in main
filemanager manager = new filemanager(); console.writeline("parsing started..."); manager.trace = (msg)=>console.writeline(msg); new thread(()=>{manager.parsefile();}).start(); // console.writeline("parsing finished."); let file parser emit message
Comments
Post a Comment