Click here to Skip to main content
15,913,709 members
Home / Discussions / C#
   

C#

 
GeneralRe: request: fixing a codeproject programm Pin
dojohansen23-Nov-09 10:50
dojohansen23-Nov-09 10:50 
QuestionAlter table in dataset Pin
daniel kuperberg20-Nov-09 6:36
daniel kuperberg20-Nov-09 6:36 
AnswerRe: Alter table in dataset Pin
dojohansen23-Nov-09 10:53
dojohansen23-Nov-09 10:53 
Questionbetter way to make function returns Pin
netJP12L20-Nov-09 6:13
netJP12L20-Nov-09 6:13 
AnswerMessage Closed Pin
20-Nov-09 6:15
stancrm20-Nov-09 6:15 
GeneralRe: better way to make function returns Pin
netJP12L20-Nov-09 6:28
netJP12L20-Nov-09 6:28 
GeneralRe: better way to make function returns [modified] Pin
Saksida Bojan20-Nov-09 6:34
Saksida Bojan20-Nov-09 6:34 
GeneralRe: better way to make function returns Pin
netJP12L20-Nov-09 6:50
netJP12L20-Nov-09 6:50 
GeneralRe: better way to make function returns Pin
Saksida Bojan20-Nov-09 6:59
Saksida Bojan20-Nov-09 6:59 
AnswerRe: better way to make function returns Pin
0x3c020-Nov-09 6:38
0x3c020-Nov-09 6:38 
AnswerRe: better way to make function returns Pin
musefan20-Nov-09 7:39
musefan20-Nov-09 7:39 
GeneralRe: better way to make function returns Pin
netJP12L20-Nov-09 8:34
netJP12L20-Nov-09 8:34 
AnswerRe: better way to make function returns Pin
dojohansen23-Nov-09 10:59
dojohansen23-Nov-09 10:59 
QuestionStream closes while reading a socket Pin
joana.simoes20-Nov-09 5:11
joana.simoes20-Nov-09 5:11 
AnswerRe: Stream closes while reading a socket Pin
Paulo Zemek20-Nov-09 5:57
Paulo Zemek20-Nov-09 5:57 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes20-Nov-09 6:19
joana.simoes20-Nov-09 6:19 
GeneralRe: Stream closes while reading a socket Pin
Paulo Zemek22-Nov-09 7:44
Paulo Zemek22-Nov-09 7:44 
AnswerRe: Stream closes while reading a socket Pin
Luc Pattyn20-Nov-09 6:27
sitebuilderLuc Pattyn20-Nov-09 6:27 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 0:13
joana.simoes23-Nov-09 0:13 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 0:39
joana.simoes23-Nov-09 0:39 
GeneralRe: Stream closes while reading a socket Pin
Luc Pattyn23-Nov-09 0:43
sitebuilderLuc Pattyn23-Nov-09 0:43 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 3:56
joana.simoes23-Nov-09 3:56 
Thanks again for the observations! There were two major issues with my approach (as you pointed):
- There is no need for asynchronous calls in the threaded implementation;
- To prevent my problem, I need to move the ProcessRequest function to threads, rather than the listening (the listening needs to be inside a thread as well, but just for the sake of not blocking the main thread, with the UI).
Having that in mind, I rewrote the Start method of the ProxyServer to look like this:


m_listener.Start();
System.Diagnostics.Debug.WriteLine("Listening socket on port " + m_port);

ThreadedListener tl = new ThreadedListener(m_listener, m_service);
Thread newThread = new Thread(new ThreadStart(tl.Process));
newThread.Start();

The listener class is now inside a thread; the Process function, refered by ThreadStart is sitting on a loop, waiting for the request; and inside this loop one thread is instantiating for each processRequest call (n.b.: this is the critical piece of code, where I actually handle the request and send it to the client and is also where the exception is thrown).

while (true)
{
    HttpListenerContext request = m_listener.GetContext();
    req myReq=new req(m_service);
    Thread newThread = new Thread(myReq.ProcessRequest);
    newThread.Start(request);
}


In a very empirical analysis, the application seems to me faster and encountering less exceptions... however I still enter the httpListenerException once in a while; This is the msdn error code:
ERROR_CONNECTION_ACTIVE
1230 (0x4CE)


And this is the description of the exception:

An invalid operation was attempted on an active network connection.


I am catching it, so in most cases is actually fine; however, the reason why I am so worried is that sometimes I am working with SSL authentication, in which case the SSL related classes send some exceptions that I cannot catch and cause my app to malfunction and eventually crash (maybe I will have to work on that problem, if I cannot solve this exception problem);
Thanks a lot,
cheers,
Jo
NewsRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 6:43
joana.simoes23-Nov-09 6:43 
AnswerRe: Stream closes while reading a socket Pin
dojohansen23-Nov-09 11:15
dojohansen23-Nov-09 11:15 
NewsRe: Stream closes while reading a socket Pin
joana.simoes24-Nov-09 1:37
joana.simoes24-Nov-09 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.