开发者

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 thi开发者_如何学编程ng 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 ?


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.


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.


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 ");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜