Click here to Skip to main content
15,920,030 members
Home / Discussions / C#
   

C#

 
AnswerRe: Ternary Condition, compiler error. Pin
Dave Kreskowiak8-Dec-05 11:38
mveDave Kreskowiak8-Dec-05 11:38 
AnswerRe: Ternary Condition, compiler error. Pin
leppie8-Dec-05 13:17
leppie8-Dec-05 13:17 
AnswerRe: Ternary Condition, compiler error. Pin
eggsovereasy12-Dec-05 10:48
eggsovereasy12-Dec-05 10:48 
Questionproblem with saving a picture as an icon Pin
g0ju8-Dec-05 10:18
g0ju8-Dec-05 10:18 
AnswerRe: problem with saving a picture as an icon Pin
NassosReyzidis9-Dec-05 0:31
NassosReyzidis9-Dec-05 0:31 
QuestionLightweight Collections Pin
OldDog.Net8-Dec-05 8:09
OldDog.Net8-Dec-05 8:09 
AnswerRe: Lightweight Collections Pin
Dave Kreskowiak8-Dec-05 11:18
mveDave Kreskowiak8-Dec-05 11:18 
QuestionAsyncronous WebRequest (race condition) Pin
usernameexists8-Dec-05 7:15
usernameexists8-Dec-05 7:15 
Hi everyone!

I got a little problem with an asyncronous WebRequest, or more precise, with its exception handler.
I'm calling a method that issues an asyncronous WebRequest and returnes its IAsyncResult to be able to wait for it lateron. Everything works fine so far, but if the host is unreachable an exception is thrown and an error message is added to my RequestState, which is returned along with the IAsyncResult. The problem is that in many cases that error message is added to the RequestState after my surrounding class received and waited for the WebRequests IAsyncResult.WaitHandle (which of cause is compleated and no error messages are found). So i'm trying for quite a while now to, 'sort of', syncronize that mechanism with a ManualResetEvent inside an asyncronously called delegate whose IAsyncResult is returned instead of the WebRequests IAsyncResult, but with no success.
I'm not very familiar with threaded applications, so i don't know exactly what to look for... so it would be great if someone could point me in the right direction.

Thanks in advance!


Below some pseudo-code with the general structure:
public void CallingMethod()<br />
{<br />
    // Calling Process() method numerous times, aquiring numerous IAsyncResults<br />
<br />
    // Iterating over all IAyncResults aquired above and waiting for each WaitHandle.<br />
<br />
    // Ups, sometimes there are no error messages in the IAyncResult.AsyncState<br />
}<br />
<br />
public IAsyncResult Process()<br />
{<br />
    IAsyncResult asyncResult = myWebRequest.BeginGetResponse(RespCallback, myRequestState);<br />
    return asyncResult;<br />
}<br />
<br />
private void RespCallback(IAsyncResult asyncResult)<br />
{<br />
    try<br />
    {<br />
        resp = req.EndGetResponse(asyncResult);<br />
    }<br />
    catch (Exception ex)<br />
    {<br />
        string errorMessage = string.Format("host unreachable...");<br />
        // Before adding this error message the WebRequests WaitHandle is released!<br />
        ((MyRequestState)asyncResult.AsyncState).AddStatusMessage(errorMessage);<br />
    }<br />
}


Variables won't; constants aren't. (Osborne's Law)
QuestionWriting to webpage from C# Pin
monrobot138-Dec-05 7:12
monrobot138-Dec-05 7:12 
AnswerRe: Writing to webpage from C# Pin
Rob Philpott8-Dec-05 7:58
Rob Philpott8-Dec-05 7:58 
GeneralRe: Writing to webpage from C# Pin
monrobot138-Dec-05 8:50
monrobot138-Dec-05 8:50 
GeneralRe: Writing to webpage from C# Pin
Rob Philpott8-Dec-05 9:13
Rob Philpott8-Dec-05 9:13 
GeneralRe: Writing to webpage from C# Pin
monrobot139-Dec-05 19:47
monrobot139-Dec-05 19:47 
GeneralRe: Writing to webpage from C# Pin
monrobot1310-Dec-05 20:17
monrobot1310-Dec-05 20:17 
GeneralRe: Writing to webpage from C# Pin
monrobot1310-Dec-05 20:46
monrobot1310-Dec-05 20:46 
AnswerRe: Writing to webpage from C# Pin
agileagent8-Dec-05 9:24
agileagent8-Dec-05 9:24 
QuestionBreak statement in C#. Pin
sacoskun8-Dec-05 6:47
sacoskun8-Dec-05 6:47 
AnswerRe: Break statement in C#. Pin
User 66588-Dec-05 7:00
User 66588-Dec-05 7:00 
GeneralRe: Break statement in C#. Pin
sacoskun8-Dec-05 7:05
sacoskun8-Dec-05 7:05 
GeneralRe: Break statement in C#. Pin
mav.northwind8-Dec-05 7:31
mav.northwind8-Dec-05 7:31 
JokeRe: Break statement in C#. Pin
akyriako788-Dec-05 7:42
akyriako788-Dec-05 7:42 
GeneralRe: Break statement in C#. Pin
Shawn Poulson8-Dec-05 8:24
Shawn Poulson8-Dec-05 8:24 
AnswerRe: Break statement in C#. Pin
agileagent8-Dec-05 10:02
agileagent8-Dec-05 10:02 
GeneralRe: Break statement in C#. Pin
sacoskun8-Dec-05 20:01
sacoskun8-Dec-05 20:01 
AnswerRe: Break statement in C#. Pin
Christian Graus8-Dec-05 10:08
protectorChristian Graus8-Dec-05 10:08 

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.