Click here to Skip to main content
16,004,727 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

Hi have a console application in main method I will call other class library method.Then actual work starts form the class library method.

My requirement is I want to display status of each method start and end in console, like
method execution started and method execution completed.

problem is all methods are in class libraries and only one method call will initiate form console main method.
eg:

consoleApp:
C#
public static void Main()
   {
     Library1.Method1();
   }


static class Library1
{
C#
public static void Method1()
   {
     Library2.Method2();
   }

}

static class Library2
{
C#
public static void Method2()
   {

   }

}

I want out put in console like:

Library1.Method1() Started.
Library1.Method1() Ended.

Library2.Method2() Started.
Library2.Method2() Ended.

not onlly method start and end in middle of the code also I need to write some status on console.

Note: only console application main method used to trigger the other methods always will have single method only.

I am not sure how to call this type of requirement or keywords to google.

Any suggestion would be much appreciated and very helpful for me.

Thanks in advance.
Posted
Comments
virusstorm 6-Jul-15 15:09pm    
Your best option is to use a BackgroundWorker with call backs. It isn't documented very well but the async and await keywords do not work well with console applications. I was at a conference last year and a Microsoft MVP demonstrated the problems with it. A lot of it has to deal with how .NET pipes messages to the console window.
Silver13 7-Jul-15 20:19pm    
I have had this issue before, like virusstorm mentioned Console applications are not quite smart enough but you can trick it by "handling" your methods using perhaps Boolean's to indicate your Start or Ends with some if statements? Its not really clean but it could do what you are asking. And yes, you would need background worker to do this.
Herman<T>.Instance 8-Jul-15 11:07am    
- You can create a public event Action<string> UpdateStatusMessage; When the event is fired the console could display it
- You could create a MessageBus

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900