Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task<ActionResult> MyController(string Id) {
- . . . .
- MyModel model = new MyModel();
- var client = new ForceClient(instanceUrl, accessToken, apiVersion);
- var qry = await client.QueryAsync<MyModel.SFOpportunity>(
- "SELECT Name, StageName FROM Opportunity where Id='" + Id + "'");
- model.Opportunity = qry.Records.FirstOrDefault();
- . . . .
- return View(viewName, myModel);
- }
- public async Task<ActionResult> MyController(string Id) {
- . . . .
- MyModel myModel = await Task.Run(() =>
- {
- var result = new MyModel(Id);
- return result;
- }); // =====> Step 1
- . . . .
- return View(viewName, myInfoView);
- }
- public class MyModel
- {
- public SFOpportunity Opportunity { get; set; }
- public MyModel(string id)
- {
- setOpportunityAsync(id);
- }
- private async void setOpportunityAsync(string id)
- {
- . . .
- var client = new ForceClient(instanceUrl, accessToken, apiVersion);
- var qry = await client.QueryAsync<MyModel.SFOpportunity>(
- "SELECT Name, StageName FROM Opportunity where Id='" + id + "'"); // ======> Step2
- Opportunity = qry.Records.FirstOrDefault(); // =====> step3
- }
- public class HasConstructorWithAsyncCall
- {
- public HasConstructorWithAsyncCall()
- {
- MarkConstructorFinishedAsync();
- }
- public bool ConstructorHasFinished { get; private set; }
- async void MarkConstructorFinishedAsync()
- {
- await Task.Delay(500);
- ConstructorHasFinished = true;
- }
- }
- [TestMethod]
- public void TestWhenConstructorFinishes()
- {
- var subject = new HasConstructorWithAsyncCall();
- Assert.IsFalse(subject.ConstructorHasFinished);
- Thread.Sleep(600);
- Assert.IsTrue(subject.ConstructorHasFinished);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement