logo
down
shadow

how to use async and await so that it will create a different task or each request


how to use async and await so that it will create a different task or each request

By : Anatoliy Svyrydenko
Date : October 17 2020, 06:10 AM
it fixes the issue I am new in asp.net core and in asynchronous programming. below is my code ,
when i run program and debug it
code :


Share : facebook icon twitter icon
How do I create a scheduler which never executes more than one Task at a time using async-await?

How do I create a scheduler which never executes more than one Task at a time using async-await?


By : Tautvydas Kersulis
Date : March 29 2020, 07:55 AM
should help you out There is a new ConcurrentExclusiveSchedulerPair type in .NET 4.5 (I don't remember if it was included in the Async CTP), and you can use its ExclusiveScheduler to restrict execution to one Task at a time.
Consider structuring your problem as a Dataflow. It's easy to just pass a TaskScheduler into the block options for the parts of the dataflow you want restricted.
code :
public static ConcurrentExclusiveSchedulerPair schedulerPair =
    new ConcurrentExclusiveSchedulerPair();
public static TaskFactory exclusiveTaskFactory =
    new TaskFactory(schedulerPair.ExclusiveScheduler);
...
public static Task RunExclusively(Action action)
{
  return exclusiveTaskFactory.StartNew(action);
}
public static Task RunExclusively(Func<Task> action)
{
  return exclusiveTaskFactory.StartNew(action).Unwrap();
}
How to use async/await in scenario with multiple tasks with each task requiring a new async/await

How to use async/await in scenario with multiple tasks with each task requiring a new async/await


By : Hors
Date : March 29 2020, 07:55 AM
this one helps. It might be more sensible to split it by customer and async within that:
code :
private async Task<Card> FindCardForCustomerAsync(string customer)
{
  var account = await _service.FindAccountAsync(customer);
  return await _service.FindCardAsync(account);
}

public async Task<Data> FindCustomersWithCards(string[] customers)
{
  var cardsTasks = customers.Select(FindCardForCustomerAsync);
  var cards = await Tasks.WhenAll(cardsTasks)
  …
}
Can I replace a call to await Task.Delay with an async method that has inside a await Task.Delay?

Can I replace a call to await Task.Delay with an async method that has inside a await Task.Delay?


By : Ernest Bruce
Date : March 29 2020, 07:55 AM
Does that help No, not really. Try increasing the delay to something like 5000 - you will clearly see the second code does not wait anymore.
This is because async void method is "fire-and-forget" - meaning once the execution reaches the first actual await it just returns and the thread continues executing while the task is underway on another thread - in this case the return is executed before the delay is up.
code :
private async Task SetMessageViewAsync()
{
   vm.Msg1 = "ABC";
   await Task.Delay(500, cts.Token);
}

// some actions
if (App.pauseCard == true)
{
    await SetMessageViewAsync();
    return;
}
// some actions
Unable to get linq query data in the async ActionResult with await and task, Error: await can't be used with async metho

Unable to get linq query data in the async ActionResult with await and task, Error: await can't be used with async metho


By : Prand
Date : March 29 2020, 07:55 AM
around this issue The compiler returns the Task for you when you use the async and await pattern, (or more precisely) when you decorate your method with the async keyword
code :
public async Task<IHttpActionResult> GetAllData(string user)
C# async / await question - getting "The return type of an async method must be void, Task or Task<T> even th

C# async / await question - getting "The return type of an async method must be void, Task or Task<T> even th


By : Barbara Miller
Date : September 21 2020, 07:00 PM
will be helpful for those in need Normally you have to return whatever you declare the function returns.
code :
Task<int> Bar()
{
    return Task.FromResult(1);
}
async Task Foo1()
{
    //No return needed.
}

async Task<int> Foo2()
{
    return 1; //Compiler converts the int to a Task<int> for you
}
async Task<Task<object>> Foo3()
{
    return Task.FromResult<object>(null);
}  
private async Task ClearDynamicSchedules(int accountID)
{
    log.Debug("Clearing existing schedules for account: " + accountID);

    string group = "AccountID:" + accountID;
    int count = 0;

    var groupMatcher = GroupMatcher<JobKey>.GroupEquals(group);
    var jobKeys = await this.Scheduler.Quartz.GetJobKeys(groupMatcher);
    foreach (var jobKey in jobKeys)
    {
        var detail = this.Scheduler.Quartz.GetJobDetail(jobKey);
        var triggers = await this.Scheduler.Quartz.GetTriggersOfJob(jobKey);
        foreach (ITrigger trigger in triggers)
        {
            await this.Scheduler.Quartz.UnscheduleJob(trigger.Key);
            count++;
        }
    }
    log.Debug("Schedules cleared for account: " + accountID + ", load schedules should follow. " + count.ToString() + " schedules removed");
    //No return
}
Related Posts Related Posts :
  • Can not convert 'string' to 'int'
  • Passing Type to Method for Use in Generic
  • Getting the value of an integer array from LIST<>
  • Parsing Html tags using c#
  • ListBox Showing First Item Only
  • developing a GUI in C# on Cosmos OS
  • How can I refactor this to work without breaking the pattern horribly?
  • Type Parameter Unification
  • Unit testing an MVC action method with a Cache dependency?
  • Finding a sequence in a List
  • How to read binary column in database into image on asp.net page?
  • Form.Show() is not showing it's child controls
  • Clearing WebBrowser control's cookies for all sites WITHOUT clearing for IE itself
  • Linq 2 Sql DateTime format to string yyyy-MM-dd
  • is there a better way to write this frankenstein LINQ query that searches for values in a child table and orders them by
  • Combine NotifyIcon and ToolTip
  • How to apply custom BidirectionalGraph from QuickGraph to GraphLayout from Graph#?
  • How do I output coloured text from by unit tests in the R# Unit Test Session window in Visual Studio?
  • C# - Getting a RawFraction Performance Counter to show a persistent value
  • Copy a ListView’s Items to the Clipboard in WPF C#
  • How to get the project path at Design Time
  • How do I parse the free format address to save into the DataBase
  • Populate StackPanel with checkbox's from Database
  • .Net/C# Build Tool - Is NAnt a preferred tool?
  • ASP.NET MVC: Localization issues (wrong resx file for culture)
  • WPF Toolkit Pie Chart Style Colors
  • .NET File locking problem
  • How to insert more than 256 columns in a Open Office Calc sheet using c#?
  • Why does FileDialog sometimes not remember the initial directory?
  • ActiveDirectory DirectorySearcher: Check if user is member of a group
  • How can I use Moq here?
  • How to copy file to the C:\Program Files (x86)\
  • Is -10 between 1.5 × 10^-45 and 3.4 × 10^38?
  • Is it possible to get the item index using Contains?
  • save System.Net.mail.MailMessage as .msg file
  • SystemParametersInfo parameter definitions for C#
  • How to add/edit functionality in the same page without flickering?
  • NHibernate generate mappings from classes?
  • How to prevent out-of-range datetime value error?
  • how to inject logger instance to every class that has a property of type ILogger using MEF
  • UDPClient First Time Using -- What's Wrong?
  • Help with debugging COM errors? (.mdi to .pdf file conversions using Microsoft Office Document Imaging)
  • Need to iterate through SQL table rows, one at a time (table too big to use adapter.Fill)
  • Why are virtual methods considered early bound?
  • programatically get public key token using .snk file c#
  • Howto place data from DataSet to List
  • C# what is the size of unmanaged object?
  • C# why sizeof is unsafe and how to get size of a struct in a safe way?
  • NullReferenceException with Ckeditor 5 and ASP.NET MVC bundle error?
  • How to refresh unc path cache?
  • dllexport Struct pointers and returning uint8_t
  • Is it a good practice to have setter in the get instance property of a singleton class
  • How to sort the coordinates of a hash set in C#
  • Multiply 64-bit integers using .NET Core's hardware intrinsics
  • How to parse string data to string and long?
  • Submit Button is not working In Razor asp.net mvc
  • While loop multiple condition check with single variable
  • Inside a catch clause, how can I see an exception without a name
  • How I can use Certificate.pfx for windows exe build
  • I'm trying to detect that SQL Server Compact Edition is installed in a system or not
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk