Hi Horst,
personally I think you should try to understand what you are writing and using.
A few samples how code should not be:
Code: Select all
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
Code: Select all
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:
Code: Select all
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:
Code: Select all
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:
Code: Select all
05:07:11 Processor 1 crashed. System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei Service.HttpServer.Response(HttpListenerContext ocontext) in C:XSharpXIDEProjectsTestProjectApplicationsWebServerPrgHttpServer.prg:Zeile 245.
bei Service.HttpServer.Processor(Int32 number, BlockingCollection`1 messages) in C:XSharpXIDEProjectsTestProjectApplicationsWebServerPrgHttpServer.prg:Zeile 91.
![04-07-2022_05-07-25.png](/phpBB3/download/file.php?id=2758&sid=5a38a2dd66002aadfdb54df610021b73)
- 04-07-2022_05-07-25.png (4.6 KiB) Viewed 940 times