![]() You are not specific about why your company is not using await. in some kind of event-dispatching loop, such as that found in Winforms or WPF. Of course, it means the calling method will need to deal with the asynchrony somehow generally the way it works is that the async gets pushed all the way back up to the top of the thread, e.g. The method calling await will return at the await statement, allowing that thread to continue execution of other code. with await, the thread is in fact freed up for other uses. Is there a way to realize the Code that the Thread can be reused while it is waiting for an answer? Doing so would address your next question: IMHO, using TaskCompletionSource with await is best. I think I can use AutoResetEvent, but is this better? The only thing that would be worse is to not call Thread.Sleep() at all. Just about any form of waiting would be better than the original code, which is waking up every 10 ms just to check a flag. My Idea was: public string Dispatch(Request data) Is there a better way to realize this? I think I can use AutoResetEvent, but is this better? Is there a way to realize the Code that the Thread can be reused while it is waiting for an answer? (I know how to do it with TaskCompletitionSource, but is this also correct for Sync Functions?) ![]() ![]() But I don't think the Code is correct (it works, but for me it looks wrong!).Īt first, this is the Code my colleague wrote: public string Dispatch(Request data) We are waiting in a Function for a Event to occur. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |