vb.net2008
پنج شنبه 29 بهمن 1388, 21:55 عصر
سلام ميشه بگيد مشكل برنامه زير چيه؟ وقتي با استفاده از اجراي خط به خط كد زير رو اجرا مي كنم درست اجرا ميشه اما وقتي دكمه start رو مي زنم هر دفعه به يه چاش اراد مي گيره. اين برنامه رو از توي Msdn برداشتم.
Imports System.Threading
Imports System.Net
Imports System
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports Microsoft.VisualBasic
Module Module1
Sub Main()
Dim prefixes() AsString = {"http://Localhost:80/"}
WhileTrue
NonblockingListener(prefixes)
EndWhile
EndSub
PublicSub NonblockingListener(ByVal prefixes() AsString)
Dim listener AsNew HttpListener
Dim result As IAsyncResult
ForEach s AsStringIn prefixes
listener.Prefixes.Add(s)
Next
listener.Start()
result = listener.BeginGetContext(New AsyncCallback(AddressOf ListenerCallback), listener)
' Applications can do some work here while waiting for the
' request. If no work can be done until you have processed a request,
' use a wait handle to prevent this thread from terminating
' while the asynchronous operation completes.
Console.WriteLine("Waiting for request to be processed asyncronously.")
result.AsyncWaitHandle.WaitOne()
Console.WriteLine("Request processed asyncronously.")
listener.Close()
EndSub
PublicSub ListenerCallback(ByVal result As IAsyncResult)
Dim listener As HttpListener
listener = CType(result.AsyncState, HttpListener)
' Call EndGetContext to complete the asynchronous operation.
Dim context As HttpListenerContext = listener.EndGetContext(result)
Dim request As HttpListenerRequest = context.Request
' Obtain a response object.
Dim response As HttpListenerResponse = context.Response
'Construct a response
Dim responseString AsString = "<HTML><BODY> Hello world!</BODY></HTML>"
Dim buffer() AsByte = System.Text.Encoding.UTF8.GetBytes(responseString)
' Get a response stream and write the response to it.
response.ContentLength64 = buffer.Length
Dim output As System.IO.Stream = response.OutputStream
output.Write(buffer, 0, buffer.Length)
'You must close the output stream.
output.Close()
'response.Close()
EndSub
EndModule
Imports System.Threading
Imports System.Net
Imports System
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports Microsoft.VisualBasic
Module Module1
Sub Main()
Dim prefixes() AsString = {"http://Localhost:80/"}
WhileTrue
NonblockingListener(prefixes)
EndWhile
EndSub
PublicSub NonblockingListener(ByVal prefixes() AsString)
Dim listener AsNew HttpListener
Dim result As IAsyncResult
ForEach s AsStringIn prefixes
listener.Prefixes.Add(s)
Next
listener.Start()
result = listener.BeginGetContext(New AsyncCallback(AddressOf ListenerCallback), listener)
' Applications can do some work here while waiting for the
' request. If no work can be done until you have processed a request,
' use a wait handle to prevent this thread from terminating
' while the asynchronous operation completes.
Console.WriteLine("Waiting for request to be processed asyncronously.")
result.AsyncWaitHandle.WaitOne()
Console.WriteLine("Request processed asyncronously.")
listener.Close()
EndSub
PublicSub ListenerCallback(ByVal result As IAsyncResult)
Dim listener As HttpListener
listener = CType(result.AsyncState, HttpListener)
' Call EndGetContext to complete the asynchronous operation.
Dim context As HttpListenerContext = listener.EndGetContext(result)
Dim request As HttpListenerRequest = context.Request
' Obtain a response object.
Dim response As HttpListenerResponse = context.Response
'Construct a response
Dim responseString AsString = "<HTML><BODY> Hello world!</BODY></HTML>"
Dim buffer() AsByte = System.Text.Encoding.UTF8.GetBytes(responseString)
' Get a response stream and write the response to it.
response.ContentLength64 = buffer.Length
Dim output As System.IO.Stream = response.OutputStream
output.Write(buffer, 0, buffer.Length)
'You must close the output stream.
output.Close()
'response.Close()
EndSub
EndModule