How best way to handle TaskCancellationException inside a Semaphore and Loop

I'm having an issue using HttpCLient.GetStringAsync().
I'm using a SemaphoreSlim to limit to one request by time... something like this:
const int MAX_REQUESTS = 1;
var semaphore = new SemaphoreSlim(MAX_REQUESTS);
Func< IEnumerable<City>, Task > getDetailsAsync = async (cities) =>
await semaphore.WaitAsync();
try
foreach (City c in cities)
string result = null;
string url = "MyUrl";
try
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(5) })
Debug.WriteLine("Consulting: " + c.code);
result = await client.GetStringAsync(url).ConfigureAwait(continueOnCapturedContext: false);
catch (TaskCanceledException e)
Debug.WriteLine("TaskCanceledException: " + e.Message);
catch (Exception ex)
Debug.WriteLine(ex.Message);
if (result != null)
// Save on local Database
catch (Exception ex)
Debug.WriteLine(ex);
finally
semaphore.Release();
var tasks = cList.Select(m => getDetailsAsync(cities));
await Task.WhenAll(tasks.ToArray()).ConfigureAwait(false);
When the user clicks the button, it goes to this code above and gets the response from server.
The problem is that sometimes "TaskCanceledException" is catch... and when this happens, the app has a strange behavior:
apparently,
it doesn't stop running... my indeterminate progress bar keeps running, but I can't interact with anything on screen, like button or pivot swipe.
I made a search on internet and I believe that this may be deadlock.
But how can I handle this exception, to continue the loop to the next city? 
Thanks!!

Hello,
It seems you want to access web url one by one using HttpClient, but sometimes the app will throw TaskCanceledException and you don’t cancel it, is it right? Please correct if I have any misunderstanding.
Can you submit a repro project for test? I have trouble to reproduce your problem. User your OneDrive and share a link here.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Best way to handle an event from WaitForSingleObject

    Hello LV experts,
    I would like to know what's the best way to handle an event which I catch using the Win32 API (WaitForSingleObject) in Labview(7.1 or 8.20).
    I know there is too many possibilities to do this, but I want to do it  on the best way. that is why I would like to have ideas and tips from you.
    Any and all tips appreciated

    You can download the Library from this link. Inside is an example that shows how to handle windows messages/events.
    http://zone.ni.com/devzone/cda/epd/p/id/4394

  • (workflow question) - What is the best way to handle audio in a large Premiere project?

    Hey all,
    This might probably be suitable for any version of Premiere, but just in case, I use CS4 (Master Collection)
    I am wrestling in my brain about the best way to handle audio in my project to cut down on the time I am working on it.
    This project I just finished was a 10 minute video for a customer shot on miniDV (HVX-200) cut down from 3 hours of tape.
    I edited my whole project down to what looked good, and then I decided I needed to clean up all the Audio using Soundbooth, So I had to go in clip by clip, using the Edit in SoundBooth --> Render and Replace method on every clip. I couldn't find a way to batch edit any audio in Soundbooth.
    For every clip, I performed similar actions---
    1) both tracks of audio were recorded with 2 different microphones (2 mono tracks), so I needed only audio from 1 track - I used SB to cut and paste the good track over the other track.
    2) amplified the audio
    3) cleaned up the background noise with the noise filter
    I am sure there has to be a better workflow option than what I just did (going clip by clip), Can someone give me some advice on how best to handle audio in a situation like this?
    Should I have just rendered out new audio for the whole tape I was using, and then edit from that?
    Should I have rendered out the audio after I edited the clips into one long track and performed the actions I needed on it? or something entirely different? It was a very slow, tedious process.
    Thanks,
    Aza

    Hi, Aza.
    Given that my background is audio and I'm just coming into the brave new world of visual bits and bytes, I would second Hunt's recommendation regarding exporting the entire video's audio as one wav file, working on it, and then reimporting. I do this as one of the last stages, when I know I have the editing done, with an ear towards consistency from beginning to end.
    One of the benefits of this approach is that you can manage all audio in the same context. For example, if you want to normalize, compress or limit your audio, doing it a clip at a time will make it difficult for you to match levels consistently or find a compression setting that works smoothly across the board. It's likely that there will instead be subtle or obvious differences between each clip you worked on.
    When all your audio is in one file you can, for instance, look at the entire wave form, see that limiting to -6 db would trim off most of the unnecessary peaks, triim it down, and then normalize it all. You may still have to do some tweaking here and there, but it gets you much farther down the road, much more easily.Same goes for reverb, EQ or other effects where you want the same feel throughout the entire video.
    Hope this helps,
    Chris

  • Best way to handle text files in OD10g

    We have a requirement to store reports in text format into a database field, to be able to view the reports, and to print them if desired using Forms 10g. What is the best way to handle this?
    - define the field in the database as clob or blob?
    - if CLOB is the choice, what tools to use to upload CLOBs to the database (since webutil transfer is for blob only)?
    - in Forms 10g, can one use the Forms data type LONG for CLOB?
    - can you do Forms search on clob and blob fields?
    - how can reports that are stored in fields be viewed without first downloading to the client workstation?
    - in Forms 10g, what is the best way to view text files residing in local PCs: "host notepad myFile"?
    Thanks much for your reply!
    gk

    Take a deep breath. Relax. All is fine.
    iDVD does not look at the size of your video file, it looks at the length. iDVD can accomodate up to 2 hours of movie
    iDVD gives you different options depending on the length of your movie. Although I won't agree with your friend about reducing the length of your movie to 15 minutes, if you could trim out a few minutes to get it under an hour that setting in iDVD (Best Performance though the new version may have renamed it) gives you the best quality. Still, any iDVD setting will give you good quality even at 64 minutes
    In FCE export as Quicktime Movie NOT any flavour of Quicktime Conversion. Select chapter markers if you have them. If everything is on one system unchecked the Make Movie Self Contained button. Drop the QT file into iDVD

  • Best way to handle when Production XI is in outrage/down

    Hi All,
    My production box is running smoothly now.If we want to go for any outrage and still we will be receiving many messages through internet from many partners.
    So we are expecting how to receive the messages when production XI is in outrage. My client is thinking of putting one more instance with the replica of Production box. So that when the main production is in outrage then immediately they can switch back to this replica version and they can process the messages untill the main one get ready.
    Now I am very much concern what are the implication will be if we go like this.
    1. which is the best way to handle XI box to maintain when the system is outrage/down?
    2. Is it a good idea of creating replica of production instance and maintaing this when the main one is in outrage?
    Kindly suggest what you guys are doing for your implementations.
    Thanks
    Seema

    >
    > 1. which is the best way to handle XI box to maintain when the system is outrage/down?(An act of extreme violence or viciousness)
    >
    XI Box - Outrage -Should be a robotic XI Box. Now I know that you are thinking what to do when cops come and handcuff it. -- Just kidding..
    Ok, here's the logic, you want to replace a piece of water pipe that gets water to your faucet. What do you do without the water leaking or disrupting the water supply... you either turn off the valve or add a temp pipe to keep the water flowing..
    So check into your sys landscape for Fail safe or High Availability, may be one of those can save you money and time.
    AB

  • Best way to handle large files in FCE HD and iDVD.

    Hi everyone,
    I have just finished working on a holiday movie that my octagenarian parents took. They presented me with about 100 minutes of raw footage that I have managed to edit down to 64 minutes. They have viewed the final version that I recorded back to tape for them. They now want to know if I can put it onto a DVD for them as well. Problem is the FCE HD file is 13Gb.
    So here is my question.
    What is the best way to handle this problem?
    I have spoken to a friend of mine who is a professional editor. She said reduce the movie duration down to about 15mins because it's probably too long and boring. (rather hurtful really) Anyway that is out of the question as far as my oldies are concerned.
    I have seen info on Toast 8 that mentions a "Fit to DVD" process that purports to "squash" 9Gb of movie to a 4.7Gb disk. I can't find if it will also put 13Gb onto a dual layer 8.5Gb disk.
    Do I have to split the movie into two parts and make two dual layer DVD's? If so I have to ask - How come "Titanic", 3hrs+ fits on one disk??
    Have I asked too many questions?

    Take a deep breath. Relax. All is fine.
    iDVD does not look at the size of your video file, it looks at the length. iDVD can accomodate up to 2 hours of movie
    iDVD gives you different options depending on the length of your movie. Although I won't agree with your friend about reducing the length of your movie to 15 minutes, if you could trim out a few minutes to get it under an hour that setting in iDVD (Best Performance though the new version may have renamed it) gives you the best quality. Still, any iDVD setting will give you good quality even at 64 minutes
    In FCE export as Quicktime Movie NOT any flavour of Quicktime Conversion. Select chapter markers if you have them. If everything is on one system unchecked the Make Movie Self Contained button. Drop the QT file into iDVD

  • Best way to handle session timeout

    Hello All,
    oracle 11g, Apex ver 3.1.2
    I am bit confused about the sessoin handling mecahnism for the users .
    Which is the best way to handle session for the users is it programatically or by DBA admin level.
    What are the pros and cons going DBA Level and Programmatica level.
    Before hand I got to have some information on hand for justification.
    thanks/kumar

    Hi,
    I've done a great deal of work with mobile accounts in Snow Leopard and I'm now having a "play" with Lion. To be honest you have to sit down and think about why you need mobile accounts.
    If your user only uses one computer then your safer having a local account backed up by a network Time Machine, this avoids the many many woes that the Servers FileSyncAgent brings to the table.
    If your users are going to be accessing multiple computers on the network and leaving the network then a mobile account is good for providing a uniform user experience and access to files etc. However, your users will have to make a choice as to whether they want their iPhoto libraries on one Local machine (backed up by Time Machine) or whether they want their library to be hosted on the server and not part of the Mobile Home Sync schedule (adding ~/Pictures to the excluded items on the home sync settings).
    With the latter, users will be able to access their iPhoto libraries on any computer when they are within the network (as it's accessed from the users server home folder).
    With the first option the user would have their iPhoto library on one computer (say the laptop they used the most) but then would not be able to access it from other computers they log on to.
    iPhoto libraries are a pain, and I'm working hard to come up with a workaround. If your users moved over to using Apeture then you could include the aperture library as part of the home sync thanks to Deeport (http://deepport.net/archives/os-x-portable-home-directories-and-syncing-flaw-wit h-bundles/)
    He does suggest that the same would work with IPhoto libraries - but it doesn't for a number of mysterious reasons regarding how the OS recognizes thie iPhoto bundle (it does so differently compared to Apeture).
    Hope this helps...

  • Best way to handle multi-page documents?

    Hi,
    I'm creating a multi-page editor on top of TLF and I'd like to hear some opinions about the best way to handle multi-pade documents.
    I'm basicaly considering two options:
    1.) A single RichEditableText and several ContainerControllers.
    2.) Several RichEditableText.
    Tks.

    I'm not sure you can create a RichEditableText and give it multiple ContainerControllers. If you use multiple RichEditableText
    components, then you will have to decide in advance which text goes in which one.
    We have posted sample code for doing this in straight ActionScript, which you could presumably also host inside a Flex container. See:
    http://blogs.adobe.com/tlf/examples/
    Look for "ActionScript Pagination Example".
    - robin

  • Best way to handle tcMultipleMatchFoundException

    Can any one tell me what is the best way to handle tcMultipleMatchFoundException during Reconciliaiton.
    One way which i know is to manually correct the data. Apart form is there any way..?
    Thanks,
    Venkatesh.

    Hi,
    I've done a great deal of work with mobile accounts in Snow Leopard and I'm now having a "play" with Lion. To be honest you have to sit down and think about why you need mobile accounts.
    If your user only uses one computer then your safer having a local account backed up by a network Time Machine, this avoids the many many woes that the Servers FileSyncAgent brings to the table.
    If your users are going to be accessing multiple computers on the network and leaving the network then a mobile account is good for providing a uniform user experience and access to files etc. However, your users will have to make a choice as to whether they want their iPhoto libraries on one Local machine (backed up by Time Machine) or whether they want their library to be hosted on the server and not part of the Mobile Home Sync schedule (adding ~/Pictures to the excluded items on the home sync settings).
    With the latter, users will be able to access their iPhoto libraries on any computer when they are within the network (as it's accessed from the users server home folder).
    With the first option the user would have their iPhoto library on one computer (say the laptop they used the most) but then would not be able to access it from other computers they log on to.
    iPhoto libraries are a pain, and I'm working hard to come up with a workaround. If your users moved over to using Apeture then you could include the aperture library as part of the home sync thanks to Deeport (http://deepport.net/archives/os-x-portable-home-directories-and-syncing-flaw-wit h-bundles/)
    He does suggest that the same would work with IPhoto libraries - but it doesn't for a number of mysterious reasons regarding how the OS recognizes thie iPhoto bundle (it does so differently compared to Apeture).
    Hope this helps...

  • Best way to handle audio and video?

    Can someone give me suggestions on best way to handle audio and video clips. 2 issues:
    Audio- I want to avoid problems for visitors who may need to install something to listen, and would like them to be able to remain viewing page while listening. I understand how to set up the Iweb player option, and I understand how to simply link to a mp3 file that relies on the visitors player. I'm thinking I need to "embed a player" (?) which is something I haven't dealt with yet.
    Video- I have a link to a .mov file. It plays it in either a real small box, or if you enlarge it , the image deteriorates. Is there a better way to handle this?
    http://www.imaginerecoveryonline.com/IMAGINERECOVERYONLINE.COM/THE_JOURNEY_1.htm l
    Thanks for any help

    Yes that should work for what you want.

  • Best way to handle any knid of exception

    Hi Experts,
    What is the best way to handle any kind of Exceptions across the layer and show a user friendly error message, for eg the JBO 2900, which is an unexpected error. There is no clue as to this error happens at which layer so how an we handle these kind of exceptions ?
    thnks

    hey you can try.. to add the exception handler.. in the task flow.. and in the DataBidnings.cpx..
    error from the controller can be got from
    ControllerContext context = ControllerContext.getInstance();
    ViewPortContext currentRootViewPort = context.getCurrentRootViewPort();
    Exception exceptionData = currentRootViewPort.getExceptionData();
    if (currentRootViewPort.isExceptionPresent()) {
    exceptionData.printStackTrace();
    currentRootViewPort.clearException();
    //FacesContext facesContext = FacesContext.getCurrentInstance();
    //facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, exceptionData.getMessage(), null));
    and the ui message can be thrown by
    FacesContext ctx = NavigationUtil.getFacesContext();
    FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,message,null);
    ctx.addMessage(null, fm);

  • Best way to handle scrolling on iphone?

    What's the best way to handle scrolling? The ios has a specific style of scrolling, click and drag, with a sort of elastic effect at the limits. What's the best way to appraoch this? Create a script that mimics this same behavior?
    In a related question, I have a list of buttons, which will scroll. I want to click the buttons, but I also want to drag the list. How best to handle this. If I have an event waiting for a click or a mouseup on the button, if I execute a drag I don't want to activate a button at the end of a drag.

    To answer your first question, I use the iPhoneScroll class by Shine Draw. Its not 100% identical to the actual iPhone scroller but comes pretty damn close and works quite nicely on the iPhone4.
    To achieve what you described in your second question, you would have to edit the class for this, it does not support interactive content.
    Hope this helps.
    Cheers

  • Best way to handle mobile accounts with large itunes/photo libraries

    What is the best way to handle mobile accounts, but not syncing itunes/photos libraries?
    I have a time capsule so I can move itunes and photos libraries for each user if need be.
    Thanks!

    Hi,
    I've done a great deal of work with mobile accounts in Snow Leopard and I'm now having a "play" with Lion. To be honest you have to sit down and think about why you need mobile accounts.
    If your user only uses one computer then your safer having a local account backed up by a network Time Machine, this avoids the many many woes that the Servers FileSyncAgent brings to the table.
    If your users are going to be accessing multiple computers on the network and leaving the network then a mobile account is good for providing a uniform user experience and access to files etc. However, your users will have to make a choice as to whether they want their iPhoto libraries on one Local machine (backed up by Time Machine) or whether they want their library to be hosted on the server and not part of the Mobile Home Sync schedule (adding ~/Pictures to the excluded items on the home sync settings).
    With the latter, users will be able to access their iPhoto libraries on any computer when they are within the network (as it's accessed from the users server home folder).
    With the first option the user would have their iPhoto library on one computer (say the laptop they used the most) but then would not be able to access it from other computers they log on to.
    iPhoto libraries are a pain, and I'm working hard to come up with a workaround. If your users moved over to using Apeture then you could include the aperture library as part of the home sync thanks to Deeport (http://deepport.net/archives/os-x-portable-home-directories-and-syncing-flaw-wit h-bundles/)
    He does suggest that the same would work with IPhoto libraries - but it doesn't for a number of mysterious reasons regarding how the OS recognizes thie iPhoto bundle (it does so differently compared to Apeture).
    Hope this helps...

  • Best Ways to Handle Multiple Users

    First post....heres my question. Can anyone help me determine the best way to handle multiple users in itunes? Some Background:
    My family shares one computer. We have on folder on the hard drive where we keep all our music files. I got an ipod and itunes and added some of the music to itunes and have pretty much used itunes for my music.
    Now my girlfriend got an ipod and I am hoping to somehow keep her music away from mine so to speak. So that I can keep synching my ipod without adding a bunch of music I dont want.
    Is there a way to handle this? So thankfull for any help!

    There is an apple article on this here:
    http://docs.info.apple.com/article.html?artnum=300432
    It sounds as though method 1 would be best for you.
    Also see how to keep the music files in one place to avoid duplication:
    http://docs.info.apple.com/article.html?artnum=93195

  • Best way of handling large amounts of data movement

    Hi
    I like to know what is the best way to handle data in the following scenario
    1. We have to create Medical and Rx claims Tables for 36 months of data about 150 million records each - First month (month 1, 2, 3, 4, .......34, 35, 36)
    2. We have to add the DELTA of month two to the 36 month baseline. But the application requirement is ONLY 36 months, even though the current size is 37 months.
    3 Similarly in the 3rd month we will have 38 months, 4th month will have 39 months.
    4. At the end of 4th month - how can I delete the First three months of data from Claim files without affecting the performance which is a 24X7 Online system.
    5. Is there a way to create Partitions of 3 months each and that can be deleted - Delete Partition number 1, If this is possible, then what kind of maintenance activity needs to be done after deleting partition.
    6. Is there any better way of doing the above scenario. What other options do I have.
    7 My goal is to eliminate the initial months data from system as the requirement is ONLY 36 months data.
    Thanks in advance for your suggestion
    sekhar

    Hi,
    You should use table partitioning to keep your data on monthly partitions. Serach on table partitioning for detailed examples.
    Regards

Maybe you are looking for

  • Colored Calendars on iPhone--And how they don't work.

    Ok. Let me start by asking Steve and Apple, "***?!" I use colored calendars. They help [me]. I can visually look at my week view and determine how much of my week consists of work, and how much consists of play. Oh, and look, there's my silver calend

  • GOT STUCK IN MAKE TO ORDER SCENARIO

    Dear All, Ours is a Make to order concept where in PP would run MRP against a sale order and as a result planned orders will get generated. we under MM will convert those Plnd orders into PR'S using MD15.while doing so it is obvious that system will

  • Deletion of Purchase requisition thru tcode MEMASSRQ

    Hi experts, In table MASSFLDLST I have done the following modification thru tcode sm30 Create : - object type = BUS2105 Table name = EBAN field name = LOEKZ The field LOEKZ is now appearing in the tcode MEMASSRQ.  But when we execute it, the square b

  • Field for HR extractor

    Hi All, I am looking for some field for Time and labour based 0PT_C01cube .In reports I need to have Shift (day or night)  and absence type as well. Can someone help me to get the mapping for this field from R/3 to BW if exists else I will have to go

  • ERROR: Context Value Management Failed

    Hi, While running autoconfig, i am getting below error ================================= ./adautocfg.sh Enter the APPS user password : Context Value Management will now update the Context file Exception in thread "main" java.lang.NoSuchMethodError: o