Sudantha
Sudantha

Reputation: 16194

C# Static methods and Console

hi i have a static method in a class , in my console application i use like as this

Console.writeLine("Some thing Some thing");

Console.writeLine("Some thing Some thing");

String X=ClassName.Method(Para); <--- Check here


Console.writeLine("Some thing after some thing ");

Console.writeLine("Some thing after some thing ");

My problem is After execution of the static method code after that are not get executed after getting the return value of the statc method application is like halted .. how to overcome this ?

Upvotes: 0

Views: 265

Answers (3)

JohnD
JohnD

Reputation: 14757

Your method might be throwing an exception or blocking (not returning).

To tell if an exception is thrown, put a try/catch around your method and print out any exceptions in the catch block.

try
{    
String X=ClassName.Method(Para); <--- Check here
}
catch (Exception e)
{
Console.WriteLine("{0}", e);
}

If your method is simply not returning (e.g. it could be blocked on a Console.ReadLine) then you will need to step through in the debugger to see why.

Also, if this is the first time the "ClassName" class is being accessed, you might be running a static constructor ("type constructor"). Sometimes it's not obvious that type constructor code is being run, but if you're doing something which might block there, this could also be your problem, not just the "Method" method.

Upvotes: 4

Bibhu
Bibhu

Reputation: 4081

Try this to find if any thing wrong is happening inside the calling function :

Console.writeLine("Some thing Some thing");    
Console.writeLine("Some thing Some thing");    

try
{    
String X=ClassName.Method(Para); <--- Check here
}    

catch(Exception e)
{
Console.writeLine(e.Message);
}

Console.writeLine("Some thing after some thing ");    
Console.writeLine("Some thing after some thing ");

Upvotes: 1

Bas
Bas

Reputation: 27095

The problem with halting the application lies in the ClassName.Method(Para) call, if that method blocks your application you should look further in there.

Upvotes: 2

Related Questions