Hi Horst,
personally I think you should try to understand what you are writing and using.
A few samples how code should not be:
function Start (args as string [] ) as void
Console:WriteLine(args [1])
If someone tries to start your executable without parameters, it will terminate with a runtime error.
IMHO you should write code like this
if args:Length > 0 .and. args[1]:Length >= 2
cArg := args[1]
else
cArg := "-80"
Console.WriteLine( "Error: application has to be started with the port as parameter '-80' is the default" )
endif
Console:WriteLine(cArg)
Another sample, as I wrote before:
private method HandleRequests() as void
local context as HttpListenerContext
self:httpListener:Start()
try
while self:httpListener:IsListening
Console.WriteLine("The Linstener Is Listening!")
context := self:httpListener:GetContext()
self:messages:Add(context)
Console.WriteLine("The Linstener has added a message!")
end while
catch e as Exception
Console.WriteLine(e:Message)
end try
You yhould move the "self:httpListener:Start()" inside the try - catch block because otherwise you will not be notified if the application gives a runtime error inside that statement:
private method HandleRequests() as void
local context as HttpListenerContext
try
self:httpListener:Start()
while self:httpListener:IsListening
Console.WriteLine("The Linstener Is Listening!")
context := self:httpListener:GetContext()
self:messages:Add(context)
Console.WriteLine("The Linstener has added a message!")
end while
catch e as Exception
Console.WriteLine(e:Message)
end try
I'm far away from being an expert in the .NET Framework programming, so my samples are far from being perfect, but they should give you an idea what you can make better.
Wolfgang
P.S. and yes, when compiled with X# the output is shown in the browser, but there is also a runtime error:
05:07:11 Processor 1 crashed. System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei Service.HttpServer.Response(HttpListenerContext ocontext) in C:\XSharp\XIDE\Projects\TestProject\Applications\WebServer\Prg\HttpServer.prg:Zeile 245.
bei Service.HttpServer.Processor(Int32 number, BlockingCollection`1 messages) in C:\XSharp\XIDE\Projects\TestProject\Applications\WebServer\Prg\HttpServer.prg:Zeile 91.