TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Praveen Kumar
NA
235
22.1k
How to use Asynch instead of synchcronous
Jul 13 2020 1:18 AM
Hi,
How to use
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult ReRunFailedSelectedBilling(List<BillingFailedViewModel> FailedGroups)
{
if
(_logger.IsInfoEnabled)
_logger.LogInfo(
string
.Format(
"Entering ReRunFailedSelectedBilling"
));
List<BillingFailedViewModel> CGs = FailedGroups.Where(x => x.ReRunFlag).ToList();
// Re-using code to get something working for GPSI. This should actually remove all the CGs and then process a single WFR. For now, we'll process one WFR for each CG...
foreach
(BillingFailedViewModel group
in
CGs)
{
using
(var dbContextScope = _dbContextScopeFactory.Create())
{
ReRunModel run =
new
ReRunModel((
int
)group.Id, DbConnection, ServerURL);
var login = HttpContext.User.Identity.Name;
run.Reject(login);
if
(run._Status.Success ==
false
)
{
TempData[
"Failure"
] =
"Error in rejection. Failed to reject."
;
}
else
{
// Create a new workflow request and re-run
var wfr = run.SetWorkflowRequest();
dbContextScope.SaveChanges();
run.WorkflowRequestId = wfr.Id;
run.Run(run.RunSychronousService(), login); Question : How to use Asynch instead of synchcronous
}
}
}
}
Asynch Method available in class - startrunmodel.cs
public
async Task RunAsync(
string
login)
{
logger.LogInfo(
string
.Format(
"PERF RunAsync starting"
));
// Kick off the server job
string
customer = wfRepo.GetCurrentUserCustomer(_User.WindowsUserName).Customer.Code;
ServiceStatus status =
new
ServiceStatus { Success =
false
, Message =
"Run failed."
};
Task[] wfrTasks =
new
Task[WorkflowRequests.Count()];
int
idx = 0;
foreach
(var wfr
in
WorkflowRequests)
{
WorkflowRequest request =
new
WorkflowRequest()
{
WorkflowRequestId = wfr.Id.ToString(),
CustomerCode = customer,
UserName = _User.WindowsUserName,
LoginName = login
};
try
{
logger.LogInfo(
string
.Format(
"PERF RequestBillingAsync {0} called"
, wfr.Id.ToString()));
wfrTasks[idx++] = _Service.RequestBillingAsync(request);
}
catch
(Exception e)
{
logger.LogError(
"RequestBilling failed "
, e);
}
logger.LogInfo(
string
.Format(
"PERF RequestBillingAsync {0} returned"
, wfr.Id.ToString()));
//_Status.Add(status);
}
//await Task.WhenAll(wfrTasks);
await Task.Yield();
logger.LogInfo(
string
.Format(
"PERF RunAsync ending "
));
// return status;
}
Reply
Answers (
3
)
How to implement LDAP in c# webforms
Cookies in asp.net mvc core.